diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 082c30ecb..c09c7a184 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,8 +1,8 @@ name: Deploy on: - #schedule: - # - cron: '5 23 * * 0' # 08:05(Mon) JST + schedule: + - cron: '5 23 * * 0' # 08:05(Mon) JST workflow_dispatch: jobs: diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 000000000..c1f0e24a9 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,4 @@ +User-agent: * +Allow: / + +Sitemap: https://https://astro-notion-blog-454.pages.dev/sitemap.xml diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index 176f8c796..9055c8387 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -68,6 +68,7 @@ if (database.Icon && database.Icon.Type === 'file') { + + `${loc}${formatDate(lastmod)}` + ) + .join('') + + return ` + + ${itemsStr} + + ` +} diff --git a/src/pages/sitemap.xml.ts b/src/pages/sitemap.xml.ts new file mode 100644 index 000000000..a9dedf23d --- /dev/null +++ b/src/pages/sitemap.xml.ts @@ -0,0 +1,24 @@ +import { generateSitemap } from '../lib/generate-sitemap' +import { getAllPosts } from '../lib/notion/client' +import { getPostLink } from '../lib/blog-helpers' + +export async function GET() { + const [posts] = await Promise.all([getAllPosts()]) + + const sitemapItems = posts.map((post) => { + const updateDate = post.UpdateDate ? new Date(post.UpdateDate) : null + const lastmod = updateDate || new Date(post.Date) + + return { + loc: new URL(getPostLink(post.Slug), import.meta.env.SITE).toString(), + lastmod, + } + }) + + const sitemap = generateSitemap(sitemapItems) + + const res = new Response(sitemap) + res.headers.set('Content-Type', 'text/xml') + + return res +}