Skip to content
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

feat(i18n): homepage link for 404 pages #1117

Merged
merged 5 commits into from
May 22, 2024

Conversation

BOJIT
Copy link
Contributor

@BOJIT BOJIT commented May 4, 2024

Hello,

This is hopefully a small non-breaking change.

This PR adds a homepage link to the 404 page.
This makes it easier to navigate to the correct page when following a dead link, particularly on mobile pages where the explorer tree is hidden.

The translations are based on Google Translate + asking some bilingual friends. Apologies if the direct translation doesn't make sense!

Copy link
Collaborator

@aarnphm aarnphm left a comment

Choose a reason for hiding this comment

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

I'm good with this change, cc @jackyzha0 for final rec.

@aarnphm aarnphm changed the title Add homepage link with internationalisation feat(i18n): homepage link for 404 pages May 4, 2024
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types"

const NotFound: QuartzComponent = ({ cfg }: QuartzComponentProps) => {
const NotFound: QuartzComponent = ({ fileData, cfg }: QuartzComponentProps) => {
const baseDir = pathToRoot(fileData.slug!)
Copy link
Owner

Choose a reason for hiding this comment

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

fileData.slug doesn't work how you expect on 404 pages due to how 404 pages work :( 404 is served differently depending on provider (i.e. some replace the page with the content of the 404 page but keep the url the same, others redirect you to 404.html) so this link isn't guaranteed to be stable/resolve to the right place

normally we would use an absolute path for this but this requires the user to set baseUrl correctly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I see :(.
Would using the baseUrl field in quartz.config.ts be acceptable, as this is an absolute URL?

Apologies, most of my previous tinkering with site generators has been through SvelteKit, which requires you to set the basePath at compile time.

Copy link
Owner

Choose a reason for hiding this comment

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

yeah should be ok to use baseUrl here imo!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have updated to use the BaseUrl config value. The link is based on the pathname portion after the domain name.
If the field is unset or doesn't contain a pathname, the link href is set to /.

Comment on lines 6 to 8
const baseDirFull = cfg.baseUrl ? cfg.baseUrl : "/"
const pathLoc = baseDirFull.indexOf("/")
const baseDir = pathLoc === -1 ? "/" : baseDirFull.substring(pathLoc)
Copy link
Owner

Choose a reason for hiding this comment

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

slightly more robust method is to construct a URL object and get the pathname

const url = new URL(`https://${cfg.baseUrl ?? "example.com"}`)
const baseDir = url.pathname

@BOJIT
Copy link
Contributor Author

BOJIT commented May 18, 2024

Have re-added Farsi support into this branch. Apologies, I didn't merge the changes in, as my v4 branch of my fork is currently being used for something else...
Currently showing up as a conflict for the added line.

@jackyzha0
Copy link
Owner

hey, please make sure the merge conflict is resolved so we can merge!

@BOJIT
Copy link
Contributor Author

BOJIT commented May 21, 2024

Oops! Another language got merged while this PR was open. I've rebased this branch off the latest upstream/v4 to resolve.

quartz/i18n/index.ts Outdated Show resolved Hide resolved
@aarnphm aarnphm merged commit 9c726ef into jackyzha0:v4 May 22, 2024
4 checks passed
@BOJIT BOJIT deleted the feature/404-link-home branch May 27, 2024 12:12
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.

None yet

3 participants