Repository navigation
Theme: Add nginx redirects template based on Aliases #95
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ecc968c
Theme: Add nginx redirects template based on Aliases
marcuspollio 0e8def6
Skip entries that would redirect a page to itself
chennes de81dd1
Support redirecting pages with redirect param
marcuspollio c6a0d30
Fix trailing slash redirects, FPN links, and CoC and Privacy settings
chennes 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
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 |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| --- | ||
| title: FreeCAD Code of Conduct | ||
| linkTitle: Conduct | ||
| draft: true | ||
| build: | ||
| render: never | ||
| aliases: ["/codeofconduct"] | ||
| redirect: https://github.com/FreeCAD/FreeCAD/blob/main/CODE_OF_CONDUCT.md | ||
| --- |
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 |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| --- | ||
| title: FreeCAD Privacy Policy | ||
| linkTitle: Privacy | ||
| draft: true | ||
| build: | ||
| render: never | ||
| aliases: ["/privacy"] | ||
| redirect: https://github.com/FreeCAD/FreeCAD/blob/main/PRIVACY_POLICY.md | ||
| --- |
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 |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| --- | ||
| title: Community | ||
| description: Get in touch with the community around the world. | ||
| aliases: ["/professional-network"] | ||
| icon: people | ||
| icon_cms: groups | ||
| --- |
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 |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| --- | ||
| title: Calendar | ||
| description: Browse all scheduled happenings. | ||
| aliases: ["/events"] | ||
| weight: 1 | ||
| icon: date | ||
| --- |
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 |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| --- | ||
| title: Development Handbook | ||
| description: Start contributing, extending, and shaping the future of the FreeCAD ecosystem. | ||
| aliases: ["/contributing"] | ||
| icon: dev | ||
| icon_cms: logo_dev | ||
| --- |
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
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
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 |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| --- | ||
| title: Addons | ||
| description: Explore FreeCAD ecosystem and take advantage of specialized tools. | ||
| aliases: ["/addons"] | ||
| weight: 3 | ||
| icon: puzzle | ||
| --- |
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
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 |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| --- | ||
| title: News | ||
| description: Browse the latest news | ||
| aliases: ["/blog"] | ||
| icon: news | ||
| icon_cms: brand_awareness | ||
| --- |
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
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,146 @@ | ||
| {{- /* | ||
| SPDX-License-Identifier: MIT | ||
| SPDX-FileCopyrightText: 2026 FreeCAD | ||
| SPDX-FileNotice: Part of the Trigo theme for Hugo. | ||
| */ -}} | ||
|
|
||
| {{- /* Nginx redirects: | ||
|
|
||
| - Get all pages with aliases or redirect param. | ||
| - Homepage also gets the old /index.php. | ||
| - Resolve targets like site links do, so pages with a `redirect` param point to their target. | ||
| - Match languages by normalized lang name without locale, e.g. es_CO -> es, zh_TW -> zh. | ||
| - Do not include equal old and new paths to avoid circular self-redirecting loop. | ||
| - Output is parsed as nginx config, so every line is checked against a safe character set. | ||
| - Generate nginx redirects map for each alias or redirect-only page. | ||
|
|
||
| @example /old, /old/, and /old.php -> /new/ | ||
| @example /old.php?lang=<lang> -> translated /<lang>/new/ or default /new/ page if translation missing | ||
| @example /?lang=<lang> -> translated homepage | ||
| @example /<lang>/internal and /<lang>/internal/ -> https://external.org/ | ||
| @example /<lang>/releases/0-17 and /<lang>/releases/0-17/ -> https://wiki.freecad.org/Release_notes_0.17/<lang> | ||
|
|
||
| */ -}} | ||
|
|
||
| {{- if site.IsDefault -}} | ||
|
|
||
| {{- $redirects := dict -}} | ||
| {{- $safe_source := `^/[A-Za-z0-9._~/%-]*(\?lang=[A-Za-z_]+)?$` -}} | ||
| {{- $safe_target := `^(/|https://)[A-Za-z0-9._~/%:?&=+()-]*$` -}} | ||
| {{- $old_locales := slice | ||
| "be" | ||
| "ca" | ||
| "cs" | ||
| "de" | ||
| "el" | ||
| "en" | ||
| "es" | ||
| "es_CO" | ||
| "eu" | ||
| "fa" | ||
| "fi" | ||
| "fr" | ||
| "ga" | ||
| "hr" | ||
| "hu" | ||
| "it" | ||
| "ja" | ||
| "ka" | ||
| "ko" | ||
| "lo" | ||
| "nl" | ||
| "pl" | ||
| "pt_BR" | ||
| "ru" | ||
| "sl" | ||
| "sr" | ||
| "sv" | ||
| "ta" | ||
| "tr" | ||
| "uk" | ||
| "zh_CN" | ||
| "zh_TW" | ||
| -}} | ||
|
|
||
| {{- range $page := hugo.Sites.Default.Pages -}} | ||
| {{- $aliases := $page.Aliases -}} | ||
|
|
||
| {{- if $page.IsHome -}} | ||
| {{- $aliases = $aliases | append "/index" -}} | ||
| {{- end -}} | ||
|
|
||
| {{- if $aliases -}} | ||
| {{- $key := partial "utils/cache_key.html" $page -}} | ||
| {{- $new_redirect := partialCached "utils/link_redirect.html" $page $key -}} | ||
| {{- $new_langs := dict -}} | ||
|
|
||
| {{- range $translation := $page.Translations -}} | ||
| {{- $normalized := replace (lower $translation.Language.Name) "_" "-" -}} | ||
| {{- $lang_name := index (split $normalized "-") 0 -}} | ||
| {{- if not (isset $new_langs $lang_name) -}} | ||
| {{- $key := partial "utils/cache_key.html" $translation -}} | ||
| {{- $lang_target := partialCached "utils/link_redirect.html" $translation $key .Language.Name -}} | ||
| {{- $new_langs = merge $new_langs (dict $lang_name $lang_target) -}} | ||
| {{- end -}} | ||
| {{- end -}} | ||
|
|
||
| {{- range $alias := $aliases -}} | ||
| {{- $alias = trim $alias "/" -}} | ||
| {{- $php_alias := printf "/%s.php" $alias -}} | ||
|
|
||
| {{- range $old_source := slice (printf "/%s" $alias) (printf "/%s/" $alias) $php_alias -}} | ||
| {{- $redirects = merge $redirects (dict $old_source $new_redirect) -}} | ||
| {{- end -}} | ||
|
|
||
| {{- $lang_sources := slice $php_alias -}} | ||
| {{- if $page.IsHome -}} | ||
| {{- $lang_sources = $lang_sources | append "/" -}} | ||
| {{- end -}} | ||
|
|
||
| {{- range $old_locale := $old_locales -}} | ||
| {{- $normalized := replace (lower $old_locale) "_" "-" -}} | ||
| {{- $lang_name := index (split $normalized "-") 0 -}} | ||
| {{- $new_target := default $new_redirect (index $new_langs $lang_name) -}} | ||
|
|
||
| {{- range $lang_source := $lang_sources -}} | ||
| {{- $redirects = merge $redirects (dict (printf "%s?lang=%s" $lang_source $old_locale) $new_target) -}} | ||
| {{- end -}} | ||
| {{- end -}} | ||
| {{- end -}} | ||
|
|
||
| {{- else if and $page.Params.redirect (ne $page.Params.redirect "auto") -}} | ||
| {{- $key := partial "utils/cache_key.html" $page -}} | ||
| {{- $new_redirect := partialCached "utils/link_redirect.html" $page $key -}} | ||
| {{- $page_source := trim $page.RelPermalink "/" -}} | ||
|
|
||
| {{- /* Include the canonical trailing-slash path, which would otherwise serve the placeholder page. */ -}} | ||
| {{- range $old_source := slice (printf "/%s" $page_source) (printf "/%s/" $page_source) -}} | ||
| {{- $redirects = merge $redirects (dict $old_source $new_redirect) -}} | ||
| {{- end -}} | ||
|
|
||
| {{- range $translation := $page.Translations -}} | ||
| {{- $key := partial "utils/cache_key.html" $translation -}} | ||
| {{- $redirect_target := partialCached "utils/link_redirect.html" $translation $key .Language.Name -}} | ||
| {{- $translated_source := trim $translation.RelPermalink "/" -}} | ||
| {{- range $old_source := slice (printf "/%s" $translated_source) (printf "/%s/" $translated_source) -}} | ||
| {{- $redirects = merge $redirects (dict $old_source $redirect_target) -}} | ||
| {{- end -}} | ||
| {{- end -}} | ||
| {{- end -}} | ||
| {{- end -}} | ||
|
|
||
| {{- range $old, $new := $redirects -}} | ||
| {{- if not (findRE $safe_source $old) -}} | ||
| {{- errorf "Redirect source %q contains characters not allowed in the nginx map" $old -}} | ||
| {{- end -}} | ||
|
|
||
| {{- if not (findRE $safe_target $new) -}} | ||
| {{- errorf "Redirect target %q for %q contains characters not allowed in the nginx map" $new $old -}} | ||
| {{- end -}} | ||
|
|
||
| {{- /* Skip equal old and new paths, which would redirect to themselves. */ -}} | ||
| {{- if ne (trim $old "/") (trim $new "/") -}} | ||
| {{- printf "%s %s;\n" $old $new -}} | ||
| {{- end -}} | ||
| {{- end -}} | ||
| {{- end -}} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one doesn't work: the section is already called "features", so this results in a circular self-redirecting loop.