-
Notifications
You must be signed in to change notification settings - Fork 13
refactor: use metadata constants for absolute URLs in website #266
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
Conversation
53ef075 to
28b06e4
Compare
|
Note: font in globals.css need to be also edited |
|
Little bit related to https://github.com/typst-jp/typst-jp.github.io/issues/233#issuecomment-3186643325 |
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.
?
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.
Metadata is centrally managed in website/src/metadata.ts. Additionally, please use the URL object for URL concatenation.
// website/src/metadata.ts
export const baseUrl = "https://typst-jp.github.io/"120094f to
f992f7d
Compare
|
Okay I think it's ready |
|
I don't see any major issues overall. |
|
If you build the website to be relative, for example to host it in a subfolder like domain.com/mytypsywebsite/ The assets links will be relative to the BASE_URL |
|
Besides, VitePress has a export const EXTERNAL_URL_RE = /^(?:[a-z]+:|\/\/)/i
/**
* Join two paths by resolving the slash collision.
*/
export function joinPath(base: string, path: string) {
return `${base}${path}`.replace(/\/+/g, '/')
}
/**
* Append base to internal (non-relative) urls
*/
export function withBase(path: string) {
return EXTERNAL_URL_RE.test(path) || !path.startsWith('/')
? path
: joinPath(siteDataRef.value.base, path)
} |
BASE_URL is the base in |
|
Excuse me, what is the proper way to build now? I've tried the following, but it doesn't work… mise run generate-docs
cd ./website/
mise exec -- bun run -- vite build --base=/sub/
mise exec -- bun run update-search-index
mise exec -- bun run preview --base=/sub/
# Then go to http://localhost:4173/sub/docs/Additionally, should https://github.com/typst-jp/typst-jp.github.io/blob/739d975e8b54c1c65158be1b242ee6809378d411/website/src/index.tsx#L29-L31 |
|
There are probably two ways to achieve this. One is to change I forgot about Pagefind. We need to handle this as well. However, it might be better to handle the search index in a separate PR. It's preferable to keep each PR small and focused. |
The - cargo test --package typst-docs --lib -- tests::test_docs --exact --nocapture
+ cargo run --package typst-docs -- --assets-dir assets/docs --out-file assets/docs.json --base /sub/docs/ |
This looks good. I'll give it a try as well. |
|
oh nice cargo commands Check again this multilang website I'm updating this MR this it's not useful anymore |
f992f7d to
9f4379b
Compare
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.
Pull Request Overview
This PR refactors hardcoded absolute URLs to use centralized metadata constants, improving maintainability by reducing duplication and making URL management more consistent across the website.
- Adds a
baseUrlconstant to the metadata configuration - Replaces hardcoded URLs in Vite configuration with dynamic URL construction
- Updates React template to use URL construction from metadata constants
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| website/src/metadata.ts | Adds baseUrl constant for centralized URL management |
| website/vite.config.ts | Updates sitemap and robots.txt configuration to use metadata constants |
| website/src/components/templates/BaseTemplate.tsx | Replaces hardcoded URLs with dynamically constructed URLs using metadata |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
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.
Thank you for your contribution. The following command allowed me to verify the display in my local environment:
git clone https://github.com/Its-Just-Nans/typst-jp.github.io.git temp
cd temp
git switch make-relative
mise trust
mise run generate
mise run dev # also `mise run preview`
|
This is a minor change, so I will merge it. |
This pull request improves how URLs are constructed and managed throughout the website by centralizing the base URL and using it to generate absolute URLs for metadata, social sharing, and links to the official Typst site. This reduces hardcoded strings, making the codebase easier to maintain and update.