-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Conversation
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.
I'm good with this change, cc @jackyzha0 for final rec.
quartz/components/pages/404.tsx
Outdated
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types" | ||
|
||
const NotFound: QuartzComponent = ({ cfg }: QuartzComponentProps) => { | ||
const NotFound: QuartzComponent = ({ fileData, cfg }: QuartzComponentProps) => { | ||
const baseDir = pathToRoot(fileData.slug!) |
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.
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
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.
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.
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.
yeah should be ok to use baseUrl here imo!
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.
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 /
.
quartz/components/pages/404.tsx
Outdated
const baseDirFull = cfg.baseUrl ? cfg.baseUrl : "/" | ||
const pathLoc = baseDirFull.indexOf("/") | ||
const baseDir = pathLoc === -1 ? "/" : baseDirFull.substring(pathLoc) |
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.
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
Have re-added Farsi support into this branch. Apologies, I didn't merge the changes in, as my |
hey, please make sure the merge conflict is resolved so we can merge! |
eb054bb
to
fc7f7b7
Compare
Oops! Another language got merged while this PR was open. I've rebased this branch off the latest |
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!