-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add Javascript licence information automatically #5297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
syeopite
merged 1 commit into
iv-org:master
from
syeopite:document-first-party-js-licenses-automatically
May 18, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
"<tr> | ||
<td><a href=\\"/#{path}\\">#{file_name}</a></td> | ||
<td><a href=\\"#{licence_link}\\">#{licence_name}</a></td> | ||
<td><a href=\\"#{source_location}\\">\#{translate(locale, "source")}</a></td> | ||
</tr>" | ||
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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.