Skip to content

Commit a51a135

Browse files
refactor: use metadata constants for absolute URLs in website (#266)
Co-authored-by: 3w36zj6 <[email protected]>
1 parent 739d975 commit a51a135

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

website/src/components/templates/BaseTemplate.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { FC, PropsWithChildren } from "hono/jsx";
2+
import { baseUrl, typstOfficialUrl } from "../../metadata";
23
import type { Page } from "../../types/model";
34
import { getTranslationStatus } from "../../utils/translationStatus";
45
import {
@@ -41,6 +42,9 @@ export const BaseTemplate: FC<BaseTemplateProps> = ({
4142
const route = page.route;
4243
const outline = page.outline;
4344
const translationStatus = getTranslationStatus(route);
45+
const absoluteRouteUrl = new URL(route, baseUrl).toString();
46+
const faviconUrl = new URL("/assets/favicon.png", baseUrl).toString();
47+
const typstOfficialRouteUrl = new URL(route, typstOfficialUrl).toString();
4448
return (
4549
<html lang="ja" class="scroll-pt-24">
4650
<head>
@@ -49,26 +53,20 @@ export const BaseTemplate: FC<BaseTemplateProps> = ({
4953
<meta name="description" content={description} />
5054
<meta name="viewport" content="width=device-width,initial-scale=1" />
5155
<meta name="theme-color" content="#239dad" />
52-
<meta
53-
property="og:url"
54-
content={`https://typst-jp.github.io${route}`}
55-
/>
56+
<meta property="og:url" content={absoluteRouteUrl} />
5657
<meta
5758
property="og:title"
5859
content={`${title} – Typstドキュメント日本語版`}
5960
/>
6061
<meta property="og:site_name" content="Typst" />
6162
<meta property="og:description" content={description} />
6263
<meta property="og:type" content="" />
63-
<meta
64-
property="og:image"
65-
content="https://typst-jp.github.io/assets/favicon.png"
66-
/>
64+
<meta property="og:image" content={faviconUrl} />
6765
<meta property="og:image:width" content="1200" />
6866
<meta property="og:image:height" content="630" />
6967
<meta name="twitter:site" content="@typstapp" />
7068
<meta name="twitter:card" content="summary_large_image" />
71-
<link rel="canonical" href={`https://typst-jp.github.io${route}`} />
69+
<link rel="canonical" href={absoluteRouteUrl} />
7270
<meta name="robots" content="index, follow" />
7371
<link rel="sitemap" type="application/xml" href="/sitemap.xml" />
7472
<meta
@@ -184,7 +182,7 @@ export const BaseTemplate: FC<BaseTemplateProps> = ({
184182
{translationStatus !== "community" && (
185183
<div class="flex">
186184
<a
187-
href={`https://typst.app${route}`}
185+
href={typstOfficialRouteUrl}
188186
target="_blank"
189187
rel="noopener noreferrer"
190188
class="inline-flex items-center text-sm underline text-gray-400 hover:text-gray-600 transition-colors"
@@ -203,7 +201,7 @@ export const BaseTemplate: FC<BaseTemplateProps> = ({
203201

204202
{translationStatus !== "community" && (
205203
<a
206-
href={`https://typst.app${route}`}
204+
href={typstOfficialRouteUrl}
207205
target="_blank"
208206
rel="noopener noreferrer"
209207
class="group inline-flex items-center px-3 py-2 rounded-md border border-gray-200 bg-white hover:border-gray-500 hover:bg-gray-50 transition-all duration-200 w-fit"

website/src/metadata.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export const githubOrganizationUrl = "https://github.com/typst-jp";
77
export const githubRepositoryUrl =
88
"https://github.com/typst-jp/typst-jp.github.io";
99
export const discordServerUrl = "https://discord.gg/9xF7k4aAuH";
10+
export const baseUrl = "https://typst-jp.github.io/";

website/vite.config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import devServer from "@hono/vite-dev-server";
77
import ssg from "@hono/vite-ssg";
88
import tailwindcss from "@tailwindcss/vite";
99
import { defineConfig } from "vite";
10+
import { baseUrl } from "./src/metadata";
1011

1112
// typst-docsが生成したドキュメントのアセットをassets/docsにシンボリックリンクする
1213
const assetsDocsPath = resolve(__dirname, "../assets/docs/");
@@ -15,17 +16,19 @@ const publicAssetsDocsPath = resolve(__dirname, "./public/assets/docs/");
1516
rmSync(publicAssetsDocsPath, { recursive: true, force: true });
1617
symlinkSync(assetsDocsPath, publicAssetsDocsPath, "dir");
1718

19+
const sitemapUrl = new URL("/sitemap.xml", baseUrl).href;
20+
1821
export default defineConfig({
1922
plugins: [
2023
tailwindcss(),
2124
ssg({
2225
plugins: [
2326
sitemapPlugin({
24-
baseUrl: "https://typst-jp.github.io/",
27+
baseUrl,
2528
}),
2629
robotsTxtPlugin({
2730
rules: [{ userAgent: "*", allow: ["/"] }],
28-
sitemapUrl: "https://typst-jp.github.io/sitemap.xml",
31+
sitemapUrl,
2932
}),
3033
],
3134
}),

0 commit comments

Comments
 (0)