-
Notifications
You must be signed in to change notification settings - Fork 12
chore: support configuration for deployment to custom base path #271
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
@YDX-2147483647 You may be interested on this one too Related to |
I think it's a good idea to rename this repository from What do you think? @mkpoli @kimushun1101 @ultimatile @gomazarashi @YDX-2147483647 If we go with this approach, Hono SSG needs to support settings that treat subdirectories as the root. As long as typst-docs and Hono SSG have the same base URL settings, everything should continue to be hosted correctly. |
It might not be that simple.
typst-jp.github.io/website/vite.config.ts Line 13 in 739d975
This is a picayune, but my point is that a painful period of transition would be inevitable. It is best to announce the plan ont the website before taking any actions. For reference, typstyle had changed the URL of its playground twice previously without any notice or redirection. The experience was very bad. |
Yes This is why I ended up using a subdomain This repo https://github.com/typst-jp/typst-jp.github.io has a But if a repo like The other option is to create |
On GitHub Pages, the |
Yes, but I think we will need to change |
I have created a repository for experimental purposes: https://github.com/typst-jp/docs (This will be deleted before the official migration in order to make redirection from the current repository work.) Currently, the contents of this repository are deployed at https://typst-jp.github.io/docs/. Although there are still some tasks left, such as supporting sitemap and robots.txt, I believe you can confirm that CSS, fonts, assets, and routing are working correctly. Please note the following points: First, the assets generated by the typst-docs CLI are expected to be located at Next, in the routing definition of Hono, the base path specified by the typst-docs CLI is removed. With these changes, I believe the migration can be completed. What do you think? @YDX-2147483647 @Its-Just-Nans Note: The build works, but currently the dev server does not run. |
Hi I have two questions:
|
Oh, I forgot about Pagefind, so I'll make sure to address that as well. This repository and the feature branch are intended for minimal changes to experiment with GitHub Pages deployment. The responsibility of this feature branch is to set up configuration for subdirectory deployment, not to split out the SSG project into a separate repository. So, handling that is out of scope for this branch. cf. #271 (comment)
Please note that even after the current repository is renamed to typst-jp/docs, the SSG core itself will not be managed there. Instead, it will likely have a more appropriate repository name. |
Okay great, nice job on the Just for info, maybe the docs will be on a subdomain instead of a subfolder https://discord.com/channels/1054443721975922748/1194684809906237500/1406358626741911724 This is just a little tweak |
Remaining tasks:
|
I think it's ready for review ^^ For information my commit bf34eb6
But I see that we still have a 404 ![]() |
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’ve confirmed that it works. There are almost no issues.
Hi For now, I am waiting on some update about honojs/vite-plugins#286 :) If this is merged, some code will need rework/deletion
|
website/src/utils/path.ts
Outdated
// Remove trailing slash from base. | ||
const baseClean = basePath !== "/" ? basePath.replace(/\/+$/, "") : basePath; | ||
// Remove leading slash from path. | ||
const pathClean = path.replace(/^\/+/, ""); |
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.
Should path
really be cleaned?
- Here:
./index.html
≠index.html
=/index.html
. - URL API:
./index.html
=index.html
≠/index.html
.
Test code
>> new URL('./index.html', 'https://example.com/sub/').href
"https://example.com/sub/index.html"
>> new URL('index.html', 'https://example.com/sub/').href
"https://example.com/sub/index.html"
>> new URL('/index.html', 'https://example.com/sub/').href
"https://example.com/index.html"
>> new URL('./index.html', 'https://example.com/sub/file').href
"https://example.com/sub/index.html"
>> new URL('index.html', 'https://example.com/sub/file').href
"https://example.com/sub/index.html"
>> new URL('/index.html', 'https://example.com/sub/file').href
"https://example.com/index.html"
Url::join
in rust behaves the same.
(That crate is based on the URL Standard. However, I didn't check the real URL Standard because it's too hard to understand.)
If this part is modified, then vite.config.ts
also needs an update.
- joinPath(basePath, "@")
- joinPath(basePath, "node_modules")
+ joinPath(basePath, "/@")
+ joinPath(basePath, "/node_modules")
website/src/utils/path.ts
Outdated
* applyBasePath("/foo/bar", "baz/qux") -> "baz/qux" | ||
* ``` | ||
*/ | ||
export const applyBasePath = (basePath: string, path: string): string => { |
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.
It seems that applyBasePath
is not actually used?
if (!route.startsWith(basePath)) return route; | ||
const offset = basePath.length - (basePath.endsWith("/") ? 1 : 0); | ||
return route.slice(offset); | ||
}; |
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.
For reference, the following is the implementation of related functions in vite.
Codes
export async function fileToDevUrl(...) {
...
const base = joinUrlSegments(config.server.origin ?? '', config.decodedBase)
return joinUrlSegments(base, removeLeadingSlash(rtn))
}
export function joinUrlSegments(a: string, b: string): string {
if (!a || !b) {
return a || b || ''
}
if (a.endsWith('/')) {
a = a.substring(0, a.length - 1)
}
if (b[0] !== '/') {
b = '/' + b
}
return a + b
}
export function stripBase(path: string, base: string): string {
if (path === base) {
return '/'
}
const devBase = withTrailingSlash(base)
return path.startsWith(devBase) ? path.slice(devBase.length - 1) : path
}
export function withTrailingSlash(path: string): string {
if (path[path.length - 1] !== '/') {
return `${path}/`
}
return path
}
* @example | ||
* ```ts | ||
* joinPath("/base/", "/foo") -> "/base/foo" | ||
* joinPath("/base", "foo") -> "/base/foo" |
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.
basePath
will be passed to vite config.
I don't know if the current behavior is consistent with vite…
I thought vite accepts a base path if and only if it starts and ends with a slash (
/
or/base/
).
But its doc sayshttps://bar.com/foo/
,./
, and""
(empty string) are also acceptable.
As for/base
(without a trailing slash), what will happen is not mentioned.
Have all possibilities been tested?
If not, perhaps add a note here or in metadata.ts
?
Only
/
,/base/
,/sub/folder/
, etc. are recommended and other variants might be inconsistent with vite.
<script> | ||
import("${joinPath(basePath, "/@vite/client")}") | ||
</script> | ||
`} | ||
</head> |
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.
Co-authored-by: Y.D.X. <[email protected]>
Co-authored-by: Y.D.X. <[email protected]>
Co-authored-by: Y.D.X. <[email protected]>
Good work! I confirm that path handling is fine when base is Another issue is that a hard-coded URL was missed. See #271 (comment). |
I have rewritten the path utility. Relative paths are not considered at this time. Hardcoded logic has been removed, and the value of the base path is now respected. |
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.
Better, but there're still small bugs:
- 原文(英語)を開く is broken in a different way
basePath
starts and ends with a slash, but these two might be the same slash
website/src/utils/path.ts
Outdated
if (parts[0].startsWith("/")) { | ||
needsLeadingSlash = true; | ||
} else if (parts[0] === "") { | ||
if (firstNonEmpty?.startsWith("/")) needsLeadingSlash = true; |
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.
if (firstNonEmpty?.startsWith("/")) needsLeadingSlash = true; | |
if (firstNonEmpty.startsWith("/")) needsLeadingSlash = true; |
const typstOfficialRouteUrl = joinPath( | ||
typstOfficialDocsUrl, | ||
removeBasePath(basePath, route), | ||
); |
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.
const typstOfficialRouteUrl = joinPath( | |
typstOfficialDocsUrl, | |
removeBasePath(basePath, route), | |
); | |
const typstOfficialRouteUrl = new URL( | |
removeBasePath(basePath, route).replace(/^\//, ""), | |
typstOfficialDocsUrl, | |
).toString(); |
Otherwise, it will become https:/typst.app/docs/reference/context/
, where https://
is transformed into https:/
.
In my browser, that URL is interpreted as http://localhost:4173/typst.app/docs/reference/context/
, though I don't know why…
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 have added handling for paths starting with http(s)://
. 89b8576
website/src/metadata.ts
Outdated
export const typstOfficialUrl = "https://typst.app"; | ||
/** The official Typst documentation base URL. */ | ||
export const typstOfficialDocsUrl = "https://typst.app/docs"; |
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.
export const typstOfficialDocsUrl = "https://typst.app/docs"; | |
export const typstOfficialDocsUrl: `https://${string}/` = | |
"https://typst.app/docs/"; |
The trailing slash will affect the result of the URL API.
>> new URL('a','https://typst.app/docs/').href
"https://typst.app/docs/a"
>> new URL('a','https://typst.app/docs').href
"https://typst.app/a"
See #271 (comment)
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.
That's a good suggestion. HTTP is now also allowed, considering local environments.
Co-authored-by: Y.D.X. <[email protected]>
Co-authored-by: Y.D.X. <[email protected]>
Co-authored-by: Y.D.X. <[email protected]>
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 adds support for configuration to deploy the website to a custom base path (specifically /docs/
) instead of the root path. This enables the documentation site to be deployed as a subdirectory while maintaining proper URL generation and routing.
- Updates the build configuration to support a configurable base path (
/docs/
) - Implements path manipulation utilities for joining and removing base paths
- Modifies routing, asset loading, and URL generation to respect the configured base path
Reviewed Changes
Copilot reviewed 17 out of 27 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
website/vite.config.ts |
Updates Vite configuration to use configurable base path and adjusts SSG plugins accordingly |
website/src/utils/path.ts |
Adds utility functions for joining URL paths and removing base paths |
website/src/utils/path.test.ts |
Comprehensive test suite for path utility functions |
website/src/metadata.ts |
Introduces basePath configuration and separates origin URL from base path |
website/src/index.tsx |
Updates routing logic to handle base path removal and adds static file serving for dev mode |
website/src/globals.css |
Updates font asset URLs to remove /assets/ prefix |
website/src/components/ui/type2href.ts |
Adds trailing slashes to generated type reference URLs |
website/src/components/ui/common/SiteTitle.tsx |
Updates home link to use configured base path |
website/src/components/ui/common/SearchWindow.tsx |
Conditionally loads search assets with proper base path in production |
website/src/components/ui/common/Breadcrumbs.tsx |
Updates breadcrumb home link to use base path |
website/src/components/ui/FunctionParameters.tsx |
Updates type reference links to include base path |
website/src/components/ui/FunctionDefinition.tsx |
Updates type reference links to include base path |
website/src/components/templates/BaseTemplate.tsx |
Updates all asset URLs and links to respect base path configuration |
website/public/index.html |
Removes redirect HTML file (no longer needed) |
website/package.json |
Updates dependencies and adjusts search indexing glob pattern |
website/.gitignore |
Updates ignored paths to reflect new asset structure |
.mise.toml |
Updates task configuration to use new base path parameter |
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.
Finally there's no problem! 🎉
Update: There exist hard-coded origin and base path in markdown/rust files, and this PR will not handle them. However, I think it's acceptable.
typst-jp.github.io/docs/glossary.md
Line 14 in 88ef363
| documentation | ドキュメント | [公式ドキュメント](https://typst.app/docs)、[日本語ドキュメント](https://typst-jp.github.io/docs/)など | |
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.
Thanks to @Its-Just-Nans and @YDX-2147483647, we've made significant progress. I appreciate your hard work.
Please note that the SSG and the documentation are loosely coupled and depend only on Indeed, it would be convenient if the metadata configuration file for the SSG could also be handled by typst-docs. |
If you use mise, do normal workflows like the website.yml
if not using mise
In both case to view result