Skip to content

Commit

Permalink
Centralize most website redirects, and add features redirect. (Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
MelissaAutumn committed Jul 11, 2024
1 parent 43a685e commit c2217aa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 36 deletions.
48 changes: 12 additions & 36 deletions builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ def mkdir(path):
raise


def write_site_htaccess(renderpath: str, lang: str, redirects: dict):
"""Writes .htaccess files from a given redirects dictionary for the given language."""
for path, url_key in redirects.items():
# Normalize non-tuples
if type(path) is not tuple:
path = (path,)
path = os.path.join(renderpath, lang, *path)
redirect_path = helper.url({'LANG': lang}, url_key)
write_htaccess(path, redirect_path)


def write_htaccess_custom(path, rules: str):
"""Write an .htaccess to `path` that rewrites based on custom rules"""
os.makedirs(path, exist_ok=True)
Expand Down Expand Up @@ -433,42 +444,7 @@ def build_website(self, assets=True, notes=True):
self.render()
write_404_htaccess(self.outpath, self.lang)

# Write download page redirect
downloads_path = os.path.join(self.renderpath, self.lang, 'download')
all_releases_path = helper.url({'LANG': lang}, 'thunderbird.latest.all')
beta_releases_path = helper.url({'LANG': lang}, 'thunderbird.latest.beta')
htaccess_rule = [
'RewriteEngine On',
f'RewriteRule download/beta {beta_releases_path} [L]', # Stop testing if we get a hit on the beta rule
f'RewriteRule .* {all_releases_path}',
]
write_htaccess_custom(downloads_path, "\n".join(htaccess_rule))

# Write get-involved page redirect
get_involved_path = os.path.join(self.renderpath, self.lang, 'get-involved')
os.makedirs(get_involved_path, exist_ok=True)
write_htaccess(get_involved_path, helper.url({'LANG': self.lang}, 'thunderbird.participate'))

# Write contribute page redirect
contribute_path = os.path.join(self.renderpath, self.lang, 'contribute')
os.makedirs(contribute_path, exist_ok=True)
write_htaccess(contribute_path, helper.url({'LANG': self.lang}, 'thunderbird.participate'))

"""
Our lovingly-home-made pages live in thunderbird/128.0/*.
The releasenotes and system requirements live in thunderbird/128.0esr/*.
Going forward this will be fixed...
"""

# Write 128.0esr/whatsnew -> 128.0/whatsnew just in case
whatsnew_path = os.path.join(self.renderpath, self.lang, 'thunderbird', '128.0esr', 'whatsnew')
os.makedirs(whatsnew_path, exist_ok=True)
write_htaccess(whatsnew_path, helper.url({'LANG': self.lang}, 'thunderbird.128.whatsnew'))

# Write 128.0/releasenotes -> 128.0esr/releasenotes
releasenotes_path = os.path.join(self.renderpath, self.lang, 'thunderbird', '128.0', 'releasenotes')
os.makedirs(releasenotes_path, exist_ok=True)
write_htaccess(releasenotes_path, helper.url({'LANG': self.lang}, 'thunderbird.128esr.releasenotes'))
write_site_htaccess(self.renderpath, self.lang, settings.WEBSITE_REDIRECTS)

if lang == 'en-US':
# 404 page for root accesses outside lang dirs.
Expand Down
11 changes: 11 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,14 @@

# Filter out specific versions for the release notes page
VERSIONS_TO_FILTER = ["125.0", "126.0", "127.0"]

# Old path (excluding locale) -> helper.url key
WEBSITE_REDIRECTS = {
'download': 'thunderbird.latest.all',
('download', 'beta'): 'thunderbird.latest.beta',
'get-involved': 'thunderbird.participate',
'contribute': 'thunderbird.participate',
'features': 'thunderbird.index',
('thunderbird', '128.0esr', 'whatsnew'): 'thunderbird.128.whatsnew',
('thunderbird', '128.0', 'releasenotes'): 'thunderbird.128esr.releasenotes',
}

0 comments on commit c2217aa

Please sign in to comment.