diff options
| -rw-r--r-- | .github/workflows/ci.yml | 13 | ||||
| -rw-r--r-- | .github/workflows/stale.yml | 3 | ||||
| -rw-r--r-- | For-Matrix-org-Support.md | 3 | ||||
| -rw-r--r-- | assets/css/default.css | 2 | ||||
| -rw-r--r-- | locales/el.json | 2 | ||||
| -rw-r--r-- | locales/eu.json | 2 | ||||
| -rw-r--r-- | locales/fa.json | 2 | ||||
| -rw-r--r-- | locales/fi.json | 2 | ||||
| -rw-r--r-- | locales/is.json | 2 | ||||
| -rw-r--r-- | locales/pt-PT.json | 2 | ||||
| -rw-r--r-- | locales/si.json | 2 | ||||
| -rw-r--r-- | scripts/git/pre-commit | 23 | ||||
| -rw-r--r-- | scripts/propagate-new-locale-keys.cr | 95 | ||||
| -rw-r--r-- | src/invidious/helpers/i18n.cr | 2 | ||||
| -rw-r--r-- | src/invidious/helpers/youtube_api.cr | 2 | ||||
| -rw-r--r-- | src/invidious/routes/search.cr | 51 | ||||
| -rw-r--r-- | src/invidious/views/search_homepage.ecr | 2 |
17 files changed, 172 insertions, 38 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 54e70d0a..99aac794 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,19 @@ on: - "api-only" pull_request: branches: "*" + paths-ignore: + - "*.md" + - LICENCE + - TRANSLATION + - invidious.service + - .git* + - .editorconfig + + - screenshots/* + - assets/** + - config/** + - .github/ISSUE_TEMPLATE/* + - kubernetes/** jobs: build: diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index e452274b..22831ea2 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -14,9 +14,10 @@ jobs: with: repo-token: ${{ secrets.GITHUB_TOKEN }} days-before-stale: 365 + days-before-pr-stale: 45 # PRs should be active. Anything that hasn't had activity in more than 45 days should be considered abandoned. days-before-close: 30 stale-issue-message: 'This issue has been automatically marked as stale and will be closed in 30 days because it has not had recent activity and is much likely outdated. If you think this issue is still relevant and applicable, you just have to post a comment and it will be unmarked.' - stale-pr-message: 'This pull request has been automatically marked as stale and will be closed in 30 days because it has not had recent activity and is much likely outdated. If you think this pull request is still relevant and applicable, you just have to post a comment and it will be unmarked.' + stale-pr-message: 'This pull request has been automatically marked as stale and will be closed in 30 days because it has not had recent activity and is much likely abandoned or outdated. If you think this pull request is still relevant and applicable, you just have to post a comment and it will be unmarked.' stale-issue-label: "stale" stale-pr-label: "stale" ascending: true diff --git a/For-Matrix-org-Support.md b/For-Matrix-org-Support.md deleted file mode 100644 index 1d61a849..00000000 --- a/For-Matrix-org-Support.md +++ /dev/null @@ -1,3 +0,0 @@ -Email address used to contact support[at]matrix[dot]org: - -TheFrenchGhosty[at]posteo[dot]is diff --git a/assets/css/default.css b/assets/css/default.css index 07a879bb..1d62bc01 100644 --- a/assets/css/default.css +++ b/assets/css/default.css @@ -488,7 +488,7 @@ body.dark-theme { the hr element is rendered improperly within one. See https://stackoverflow.com/a/34372979 for more info */ hr { - margin: auto 0 auto 0; + margin: 10px 0 10px 0; } /* Description Expansion Styling*/ diff --git a/locales/el.json b/locales/el.json index 26e7fcaa..c55db8ef 100644 --- a/locales/el.json +++ b/locales/el.json @@ -416,4 +416,4 @@ "hdr": "", "filter": "", "Current version: ": "Τρέχουσα έκδοση: " -}
\ No newline at end of file +} diff --git a/locales/eu.json b/locales/eu.json index 8381f496..ff1c67b7 100644 --- a/locales/eu.json +++ b/locales/eu.json @@ -338,4 +338,4 @@ "Playlists": "", "Community": "", "Current version: ": "" -}
\ No newline at end of file +} diff --git a/locales/fa.json b/locales/fa.json index 5e540b7d..f8c33b8f 100644 --- a/locales/fa.json +++ b/locales/fa.json @@ -416,4 +416,4 @@ "hdr": "", "filter": "", "Current version: ": "نسخه فعلی: " -}
\ No newline at end of file +} diff --git a/locales/fi.json b/locales/fi.json index 62e96639..2092e994 100644 --- a/locales/fi.json +++ b/locales/fi.json @@ -416,4 +416,4 @@ "hdr": "", "filter": "", "Current version: ": "Tämänhetkinen versio: " -}
\ No newline at end of file +} diff --git a/locales/is.json b/locales/is.json index 00d50ad1..a847080a 100644 --- a/locales/is.json +++ b/locales/is.json @@ -416,4 +416,4 @@ "hdr": "", "filter": "", "Current version: ": "Núverandi útgáfa: " -}
\ No newline at end of file +} diff --git a/locales/pt-PT.json b/locales/pt-PT.json index a8569f18..43ffc7d8 100644 --- a/locales/pt-PT.json +++ b/locales/pt-PT.json @@ -416,4 +416,4 @@ "hdr": "", "filter": "", "Current version: ": "Versão atual: " -}
\ No newline at end of file +} diff --git a/locales/si.json b/locales/si.json index a9889672..57ed22a3 100644 --- a/locales/si.json +++ b/locales/si.json @@ -416,4 +416,4 @@ "hdr": "", "filter": "", "Current version: ": "" -}
\ No newline at end of file +} diff --git a/scripts/git/pre-commit b/scripts/git/pre-commit new file mode 100644 index 00000000..e4a27750 --- /dev/null +++ b/scripts/git/pre-commit @@ -0,0 +1,23 @@ +# Useful precomit hooks +# Please see https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks for instructions on installation. + +# Crystal linter +# This is a modified version of the pre-commit hook from the crystal repo. https://github.com/crystal-lang/crystal/blob/master/scripts/git/pre-commit +# Please refer to that if you'd like an version that doesn't automatically format staged files. +changed_cr_files=$(git diff --cached --name-only --diff-filter=ACM | grep '\.cr$') +if [ ! -z "$changed_cr_files" ]; then + if [ -x bin/crystal ]; then + # use bin/crystal wrapper when available to run local compiler build + bin/crystal tool format $changed_cr_files >&2 + else + crystal tool format $changed_cr_files >&2 + fi + + git add $changed_cr_files +fi + +# Locale equalizer +if [ ! -z $(git diff --name-only --cached -- locales/) ]; then + crystal run scripts/propagate-new-locale-keys.cr + git add locales > /dev/null +fi
\ No newline at end of file diff --git a/scripts/propagate-new-locale-keys.cr b/scripts/propagate-new-locale-keys.cr new file mode 100644 index 00000000..570b408a --- /dev/null +++ b/scripts/propagate-new-locale-keys.cr @@ -0,0 +1,95 @@ +require "json" +require "../src/invidious/helpers/i18n.cr" + +def locale_to_array(locale_name) + arrayifed_locale_data = [] of Tuple(String, JSON::Any | String) + keys_only_array = [] of String + LOCALES[locale_name].each do |k, v| + if v.as_h? + arrayifed_locale_data << {k, JSON.parse(v.as_h.to_json)} + elsif v.as_s? + arrayifed_locale_data << {k, v.as_s} + end + + keys_only_array << k + end + + return arrayifed_locale_data, keys_only_array +end + +# Invidious currently has some unloaded localization files. We shouldn't need to propagate new keys onto those. +# We'll also remove the reference locale (english) from the list to process. +loaded_locales = LOCALES.keys.select! { |key| key != "en-US" } +english_locale, english_locale_keys = locale_to_array("en-US") + +# In order to automatically propagate locale keys we're going to be needing two arrays. +# One is an array containing each locale data encoded as tuples. The other would contain +# sets of only the keys of each locale files. +# +# The second array is to make sure that an key from the english reference file is present +# in whatever the current locale we're scanning is. +locale_list = [] of Array(Tuple(String, JSON::Any | String)) +locale_list_with_only_keys = [] of Array(String) + +# Populates the created arrays from above +loaded_locales.each do |name| + arrayifed_locale_data, keys_only_locale = locale_to_array(name) + + locale_list << arrayifed_locale_data + locale_list_with_only_keys << keys_only_locale +end + +# Propagate additions +locale_list_with_only_keys.dup.each_with_index do |keys_of_locale_in_processing, index_of_locale_in_processing| + insert_at = {} of Int32 => Tuple(String, JSON::Any | String) + + LOCALES["en-US"].each_with_index do |ref_locale_data, ref_locale_key_index| + ref_locale_key, ref_locale_value = ref_locale_data + + # Found an new key that isn't present in the current locale.. + if !keys_of_locale_in_processing.includes? ref_locale_key + # In terms of structure there's currently only two types; one for plural and the other for singular translations. + if ref_locale_value.as_h? + insert_at[ref_locale_key_index] = {ref_locale_key, JSON.parse({"([^.,0-9]|^)1([^.,0-9]|$)" => "", "" => ""}.to_json)} + else + insert_at[ref_locale_key_index] = {ref_locale_key, ""} + end + end + end + + insert_at.each do |location_to_insert, data| + locale_list_with_only_keys[index_of_locale_in_processing].insert(location_to_insert, data[0]) + locale_list[index_of_locale_in_processing].insert(location_to_insert, data) + end +end + +# Propagate removals +locale_list_with_only_keys.dup.each_with_index do |keys_of_locale_in_processing, index_of_locale_in_processing| + remove_at = [] of Int32 + + keys_of_locale_in_processing.each_with_index do |current_key, current_key_index| + if !english_locale_keys.includes? current_key + remove_at << current_key_index + end + end + + remove_at.each do |index_to_remove_at| + locale_list_with_only_keys[index_of_locale_in_processing].delete_at(index_to_remove_at) + locale_list[index_of_locale_in_processing].delete_at(index_to_remove_at) + end +end + +# Now we convert back to our original format. +final_locale_list = [] of String +locale_list.each do |locale| + intermediate_hash = {} of String => (JSON::Any | String) + locale.each { |k, v| intermediate_hash[k] = v } + final_locale_list << intermediate_hash.to_pretty_json(indent = " ") +end + +locale_map = Hash.zip(loaded_locales, final_locale_list) + +# Export +locale_map.each do |locale_name, locale_contents| + File.write("locales/#{locale_name}.json", "#{locale_contents}\n") +end diff --git a/src/invidious/helpers/i18n.cr b/src/invidious/helpers/i18n.cr index 45a3f1ae..dd46feab 100644 --- a/src/invidious/helpers/i18n.cr +++ b/src/invidious/helpers/i18n.cr @@ -21,7 +21,7 @@ LOCALES = { "pt-PT" => load_locale("pt-PT"), "ro" => load_locale("ro"), "ru" => load_locale("ru"), - "sv" => load_locale("sv-SE"), + "sv-SE" => load_locale("sv-SE"), "tr" => load_locale("tr"), "uk" => load_locale("uk"), "zh-CN" => load_locale("zh-CN"), diff --git a/src/invidious/helpers/youtube_api.cr b/src/invidious/helpers/youtube_api.cr index 544e635b..e27d4088 100644 --- a/src/invidious/helpers/youtube_api.cr +++ b/src/invidious/helpers/youtube_api.cr @@ -79,7 +79,7 @@ end def request_youtube_api_search(search_query : String, params : String, region = nil) # JSON Request data, required by the API data = { - "query" => URI.encode_www_form(search_query), + "query" => search_query, "context" => make_youtube_api_context(region), "params" => params, } diff --git a/src/invidious/routes/search.cr b/src/invidious/routes/search.cr index a993a17a..513904b8 100644 --- a/src/invidious/routes/search.cr +++ b/src/invidious/routes/search.cr @@ -20,15 +20,17 @@ class Invidious::Routes::Search < Invidious::Routes::BaseRoute query = env.params.query["search_query"]? query ||= env.params.query["q"]? - query ||= "" - page = env.params.query["page"]?.try &.to_i? - page ||= 1 + page = env.params.query["page"]? - if query - env.redirect "/search?q=#{URI.encode_www_form(query)}&page=#{page}" + if query && !query.empty? + if page && !page.empty? + env.redirect "/search?q=" + URI.encode_www_form(query) + "&page=" + page + else + env.redirect "/search?q=" + URI.encode_www_form(query) + end else - env.redirect "/" + env.redirect "/search" end end @@ -38,28 +40,31 @@ class Invidious::Routes::Search < Invidious::Routes::BaseRoute query = env.params.query["search_query"]? query ||= env.params.query["q"]? - query ||= "" - return env.redirect "/" if query.empty? + if !query || query.empty? + # Display the full page search box implemented in #1977 + env.set "search", "" + templated "search_homepage", navbar_search: false + else + page = env.params.query["page"]?.try &.to_i? + page ||= 1 - page = env.params.query["page"]?.try &.to_i? - page ||= 1 + user = env.get? "user" - user = env.get? "user" + begin + search_query, count, videos, operators = process_search_query(query, page, user, region: region) + rescue ex + return error_template(500, ex) + end - begin - search_query, count, videos, operators = process_search_query(query, page, user, region: nil) - rescue ex - return error_template(500, ex) - end + operator_hash = {} of String => String + operators.each do |operator| + key, value = operator.downcase.split(":") + operator_hash[key] = value + end - operator_hash = {} of String => String - operators.each do |operator| - key, value = operator.downcase.split(":") - operator_hash[key] = value + env.set "search", query + templated "search" end - - env.set "search", query - templated "search" end end diff --git a/src/invidious/views/search_homepage.ecr b/src/invidious/views/search_homepage.ecr index 8927c3f1..7d2dab83 100644 --- a/src/invidious/views/search_homepage.ecr +++ b/src/invidious/views/search_homepage.ecr @@ -1,7 +1,7 @@ <% content_for "header" do %> <meta name="description" content="<%= translate(locale, "An alternative front-end to YouTube") %>"> <title> - Invidious + Invidious - <%= translate(locale, "search") %> </title> <link rel="stylesheet" href="/css/empty.css?v=<%= ASSET_COMMIT %>"> <% end %> |
