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

@inox-tools/sitemap-ext 활성화 및 동적 페이지들에 대한 사이트맵 생성 #467

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import * as path from "node:path";

import mdx from "@astrojs/mdx";
import preact from "@astrojs/preact";
import sitemap from "@astrojs/sitemap";
import vercel from "@astrojs/vercel/serverless";
import sitemap from "@inox-tools/sitemap-ext";
import yaml from "@rollup/plugin-yaml";
import rehypeShiki, { type RehypeShikiOptions } from "@shikijs/rehype";
import { transformerMetaHighlight } from "@shikijs/transformers";
Expand All @@ -22,10 +22,6 @@ export default defineConfig({
customPages: ["/api/rest-v1/", "/api/rest-v2/"].map(
(url) => `https://developers.portone.io${url}`,
),
filter: (page) =>
![/^\/test/, /^\/platform/, /^\/api\/rest-v2-legacy/].some((regex) =>
regex.test(page.replace("https://developers.portone.io", "")),
),
}),
],
vite: {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"@iconify-json/ic": "^1.1.17",
"@iconify-json/material-symbols": "^1.1.78",
"@iconify-json/simple-icons": "^1.1.100",
"@inox-tools/sitemap-ext": "^0.2.11",
"@portone-io/lint-local-links-valid": "workspace:^",
"@preact/compat": "^17.1.2",
"@preact/signals": "^1.2.3",
"@rollup/plugin-yaml": "^4.1.2",
Expand Down Expand Up @@ -74,7 +76,6 @@
"httpsnippet-lite": "^3.0.5",
"js-yaml": "^4.1.0",
"json5": "^2.2.3",
"@portone-io/lint-local-links-valid": "workspace:^",
"lodash-es": "^4.17.21",
"mdast-util-from-markdown": "^2.0.0",
"mdast-util-mdx": "^3.0.0",
Expand Down
98 changes: 98 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/pages/api/rest-v1/[...slug].astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
import sitemap from "sitemap-ext:config";

import * as prose from "~/components/prose";
import LayoutBase from "~/layouts/LayoutBase.astro";
import NavMenu from "~/layouts/rest-api/nav-menu/NavMenu.astro";
Expand All @@ -9,6 +11,19 @@ import { overrideSystemVersion } from "~/state/system-version/server";

import Component from "./_Page";

sitemap(async ({ addToSitemap }) => {
const categories = getCategories(schema).flatMap((category) => [
category,
...(category.children ?? []),
]);

addToSitemap(
categories.map((category) => ({
slug: category.id,
})),
);
});

const { v1auth } = await getApiSectionDescriptions();

const { slug } = Astro.params;
Expand Down
4 changes: 4 additions & 0 deletions src/pages/api/rest-v2-legacy/index.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
---
import sitemap from "sitemap-ext:config";

sitemap(false);

return new Response(null, {
status: 301,
headers: {
Expand Down
15 changes: 15 additions & 0 deletions src/pages/api/rest-v2/[...slug].astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
import sitemap from "sitemap-ext:config";

import LayoutBase from "~/layouts/LayoutBase.astro";
import NavMenu from "~/layouts/rest-api/nav-menu/NavMenu.astro";
import { getCategories } from "~/layouts/rest-api/schema-utils/category";
Expand All @@ -7,6 +9,19 @@ import { overrideSystemVersion } from "~/state/system-version/server";

import Component from "./_Page";

sitemap(async ({ addToSitemap }) => {
const categories = getCategories(schema).flatMap((category) => [
category,
...(category.children ?? []),
]);

addToSitemap(
categories.map((category) => ({
slug: category.id,
})),
);
});

const { slug } = Astro.params;
const [_api, _rest, section = ""] = Astro.url.pathname
.split("/")
Expand Down
7 changes: 7 additions & 0 deletions src/pages/blog/posts/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { Image } from "astro:assets";
import { getCollection } from "astro:content";
import { format } from "date-fns";
import sitemap from "sitemap-ext:config";
import { match, P } from "ts-pattern";

import PostList from "~/components/blog/PostList/PostList.astro";
Expand All @@ -15,6 +16,12 @@ import authors from "~/content/blog/_authors.yaml";
import LayoutBase from "~/layouts/LayoutBase.astro";
// import NavigationMenu from "~/components/blog/NavigationMenu";

sitemap(async ({ addToSitemap }) => {
const entries = await getCollection("blog");

addToSitemap(entries.map((entry) => ({ slug: entry.slug })));
});

const { slug } = Astro.params;
const entries = await getCollection("blog").then((entries) =>
entries.sort((a, b) => b.data.date.getTime() - a.data.date.getTime()),
Expand Down
14 changes: 14 additions & 0 deletions src/pages/blog/tags/[tag].astro
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
---
import { getCollection } from "astro:content";
import sitemap from "sitemap-ext:config";

import PostListLayout from "~/components/blog/PostList/PostListLayout.astro";

sitemap(async ({ addToSitemap }) => {
const entries = await getCollection(
"blog",
(entry) =>
!entry.data.draft ||
import.meta.env.DEV ||
import.meta.env.VERCEL_ENV === "preview",
);
const tags = [...new Set(entries.flatMap((entry) => entry.data.tags))];

addToSitemap(tags.map((tag) => ({ tag })));
});

const tag = decodeURIComponent(Astro.params.tag?.toString() ?? "");
const entries = await getCollection(
"blog",
Expand Down
15 changes: 15 additions & 0 deletions src/pages/docs/[lang]/[...slug].astro
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
---
import { getCollection } from "astro:content";
import sitemap from "sitemap-ext:config";

import Docs from "~/layouts/Docs.astro";
import { getRedirection } from "~/misc/redirection";
import { isLang } from "~/type";

sitemap(async ({ addToSitemap }) => {
const entries = await getCollection("docs");

addToSitemap(
entries
.filter((entry) => !entry.slug.startsWith("en/"))
.map((entry) => {
const lang = entry.slug.split("/")[0];
const slug = entry.slug.replace(`${lang}/`, "");
return { lang, slug };
}),
);
});

const { lang, slug } = Astro.params;
if (!isLang(lang) || !slug) {
return new Response(null, { status: 404 });
Expand Down
8 changes: 8 additions & 0 deletions src/pages/release-notes/[...slug].astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
import { getCollection } from "astro:content";
import { format } from "date-fns";
import sitemap from "sitemap-ext:config";
import { match } from "ts-pattern";

import * as prose from "~/components/prose";
Expand All @@ -9,6 +11,12 @@ import LayoutBase from "~/layouts/LayoutBase.astro";
import Nav from "~/layouts/release-notes/Nav.astro";
import { getReleaseNotes } from "~/misc/releaseNote";

sitemap(async ({ addToSitemap }) => {
const entries = await getCollection("release-notes");

addToSitemap(entries.map((entry) => ({ slug: entry.slug })));
});

const { slug } = Astro.params;
if (!slug) return new Response(null, { status: 404 });
const { apiSdkNotes, consoleNotes, platformNotes } = await getReleaseNotes();
Expand Down
6 changes: 6 additions & 0 deletions src/pages/test/typography.astro
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
---
import sitemap from "sitemap-ext:config";

import * as prose from "~/components/prose";
import LayoutBase from "~/layouts/LayoutBase.astro";
import { interleave } from "~/layouts/rest-api";

export const prerender = true;

sitemap(false);

const ipsumEn = `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`;
const ipsumKo = `국교는 인정되지 아니하며, 종교와 정치는 분리된다. 중앙선거관리위원회는 법령의 범위안에서 선거관리·국민투표관리 또는 정당사무에 관한 규칙을 제정할 수 있으며, 법률에 저촉되지 아니하는 범위안에서 내부규율에 관한 규칙을 제정할 수 있다.
언론·출판에 대한 허가나 검열과 집회·결사에 대한 허가는 인정되지 아니한다. 대통령은 제1항과 제2항의 처분 또는 명령을 한 때에는 지체없이 국회에 보고하여 그 승인을 얻어야 한다.`;
Expand Down