diff --git a/scripts/generate_js_licenses.cr b/scripts/generate_js_licenses.cr new file mode 100644 index 00000000..1f4ffa62 --- /dev/null +++ b/scripts/generate_js_licenses.cr @@ -0,0 +1,56 @@ +# This file automatically generates Crystal strings of rows within an HTML Javascript licenses table +# +# These strings will then be placed within a `<%= %>` statement in licenses.ecr at compile time which +# will be interpolated at run-time. This interpolation is only for the translation of the "source" string +# so maybe we can just switch to a non-translated string to simplify the logic here. +# +# The Javascript Web Labels table defined at https://www.gnu.org/software/librejs/free-your-javascript.html#step3 +# for example just reiterates the name of the source file rather than use a "source" string. +all_javascript_files = Dir.glob("assets/**/*.js") + +videojs_js = [] of String +invidious_js = [] of String + +all_javascript_files.each do |js_path| + if js_path.starts_with?("assets/videojs/") + videojs_js << js_path[7..] + else + invidious_js << js_path[7..] + end +end + +def create_licence_tr(path, file_name, licence_name, licence_link, source_location) + tr = <<-HTML + " + #{file_name} + #{licence_name} + \#{translate(locale, "source")} + " + HTML + + # New lines are removed as to allow for using String.join and StringLiteral.split + # to get a clean list of each table row. + tr.gsub('\n', "") +end + +# TODO Use videojs-dependencies.yml to generate license info for videojs javascript +jslicence_table_rows = [] of String + +invidious_js.each do |path| + file_name = path.split('/')[-1] + + # A couple non Invidious JS files are also shipped alongside Invidious due to various reasons + next if { + "sse.js", "silvermine-videojs-quality-selector.min.js", "videojs-youtube-annotations.min.js", + }.includes?(file_name) + + jslicence_table_rows << create_licence_tr( + path: path, + file_name: file_name, + licence_name: "AGPL-3.0", + licence_link: "https://www.gnu.org/licenses/agpl-3.0.html", + source_location: path + ) +end + +puts jslicence_table_rows.join("\n") diff --git a/src/invidious/views/licenses.ecr b/src/invidious/views/licenses.ecr index 4d64ec3f..3037f3d7 100644 --- a/src/invidious/views/licenses.ecr +++ b/src/invidious/views/licenses.ecr @@ -9,90 +9,6 @@

<%= translate(locale, "JavaScript license information") %>

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + <%- {% for row in run("../../../scripts/generate_js_licenses.cr").stringify.split('\n') %} %> + <%-= {{row.id}} -%> + <% {% end %} -%>
- _helpers.js - - AGPL-3.0 - - <%= translate(locale, "source") %> -
- handlers.js - - AGPL-3.0 - - <%= translate(locale, "source") %> -
- community.js - - AGPL-3.0 - - <%= translate(locale, "source") %> -
- embed.js - - AGPL-3.0 - - <%= translate(locale, "source") %> -
- notifications.js - - AGPL-3.0 - - <%= translate(locale, "source") %> -
- player.js - - AGPL-3.0 - - <%= translate(locale, "source") %> -
silvermine-videojs-quality-selector.min.js @@ -121,34 +37,6 @@
- subscribe_widget.js - - AGPL-3.0 - - <%= translate(locale, "source") %> -
- themes.js - - AGPL-3.0 - - <%= translate(locale, "source") %> -
videojs-contrib-quality-levels.js @@ -289,103 +177,9 @@
- watch.js - - AGPL-3.0 - - <%= translate(locale, "source") %> -
- comments.js - - AGPL-3.0 - - <%= translate(locale, "source") %> -
- pagination.js - - AGPL-3.0 - - <%= translate(locale, "source") %> -
- playlist_widget.js - - AGPL-3.0 - - <%= translate(locale, "source") %> -
- post.js - - AGPL-3.0 - - <%= translate(locale, "source") %> -
- watched_indicator.js - - AGPL-3.0 - - <%= translate(locale, "source") %> -
- watched_widget.js - - AGPL-3.0 - - <%= translate(locale, "source") %> -