Skip to content

fix(doc): apply redirects to git history at load time#655

Draft
caugner wants to merge 2 commits into
mainfrom
247-apply-redirects-to-git-history
Draft

fix(doc): apply redirects to git history at load time#655
caugner wants to merge 2 commits into
mainfrom
247-apply-redirects-to-git-history

Conversation

@caugner
Copy link
Copy Markdown
Contributor

@caugner caugner commented Apr 30, 2026

Description

Update git_history, applying redirects at load time so moved pages resolve to a real history entry instead of the 1970-01-01 default.

  • Relocate GIT_HISTORY / git_history() from rari-types to a new rari-doc::git_history module.
  • For each (old_url, new_url) redirect, copy the old path's history entry to the new path (preserving any existing entry at the new path).

Motivation

Prevent the build from falling back to 1970-01-01 for translated docs that sync-translated-content moved locally during the build.

Additional details

Related issues and pull requests

Fixes #247

caugner added 2 commits April 30, 2026 16:15
Move the `GIT_HISTORY` static and `git_history()` accessor from
`rari-types::globals` into a new `rari-doc::git_history` module.
`HistoryEntry` stays in `rari-types`. Both existing call sites are
already in `rari-doc`, so this is a pure relocation with no behavior
change.

Sets up a follow-up that needs to compose `git_history` with
`rari-doc::redirects` at load time.
When `sync-translated-content` moves a translated doc to match an
updated en-US slug, the move is local to the build environment and is
never committed back to translated-content. As a result, the doc's new
path has no entry in `_git_history.json`, the build pipeline's lookup
misses, and the page footer shows `1970-01-01T00:00:00.000Z` for the
last-modified date and an empty hash for the last-commit URL.

Compose `git_history` with `redirects` at load time: for every
`(old_url, new_url)` pair, if the corresponding old file path has a
history entry and the new path doesn't, copy the entry under the new
key. Entries that already exist at the new path (e.g. from a `content
move` whose new location is committed) are preserved.
@github-actions
Copy link
Copy Markdown
Contributor

1fd8fbe was deployed to: https://rari-pr655.review.mdn.allizom.net/

@caugner caugner marked this pull request as ready for review May 4, 2026 18:15
@caugner caugner requested a review from a team as a code owner May 4, 2026 18:15
@caugner caugner requested a review from LeoMcA May 4, 2026 18:15
Copy link
Copy Markdown
Member

@LeoMcA LeoMcA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is good, I just think it's in the wrong place: see my last comment

fn load_history_files() -> HashMap<PathBuf, HistoryEntry> {
let f = content_root().join("_git_history.json");
let mut map = if let Ok(json_str) = fs::read_to_string(f) {
serde_json::from_str(&json_str).expect("unable to parse l10n json")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
serde_json::from_str(&json_str).expect("unable to parse l10n json")
serde_json::from_str(&json_str).expect("unable to parse _git_history.json")

let f = translated_root.join("_git_history.json");
if let Ok(json_str) = fs::read_to_string(f) {
let translated: HashMap<PathBuf, HistoryEntry> =
serde_json::from_str(&json_str).expect("unable to parse l10n json");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
serde_json::from_str(&json_str).expect("unable to parse l10n json");
serde_json::from_str(&json_str).expect("unable to parse _git_history.json");

Comment on lines +7 to +9
//! Redirects from `_redirects.txt` are applied at load time so that pages whose
//! source file was moved (locally by `sync-translated-content`, or in a build
//! that ran before `git-history` could pick up a `content move`) still resolve
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, we don't commit - so these redirects don't actually get put into _git_history.json, even though they exist on disk.

I'd suggest we do this resolution when we build that JSON, patching it at load time seems unnecessary and a bit confusing (that the on-disk representation differs from the in memory one).

If there's some reason we can't do it at JSON-build time, I'd at least rename the function here to clarify that it resolves to something different, maybe file_history or similar.

I'd also remove this comment and hang one off the git_history function, and make it assume a little less knowledge about the internals, something like:

Loads a map of history entries for each file, resolving redirects when files exist but aren't yet committed (as we'd expect to see during a build after sync-translated-content is run)

@caugner caugner marked this pull request as draft May 7, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Modified date of moved page (sync-translated-content) is 1970-01-01

3 participants