File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,8 @@ export const BaseTemplate: FC<BaseTemplateProps> = ({
6464 < meta name = "twitter:site" content = "@typstapp" />
6565 < meta name = "twitter:card" content = "summary_large_image" />
6666 < link rel = "canonical" href = { `https://typst-jp.github.io${ route } ` } />
67+ < meta name = "robots" content = "index, follow" />
68+ < link rel = "sitemap" type = "application/xml" href = "/sitemap.xml" />
6769 < meta
6870 name = "twitter:image:alt"
6971 content = "The left side of a text editor with colorful cursors, as well as the text 'Compose papers faster, Typst'"
Original file line number Diff line number Diff line change @@ -71,4 +71,39 @@ flattenedPages.forEach((page, pageIndex) => {
7171 } ) ;
7272} ) ;
7373
74+ app . get ( "/sitemap.xml" , ( c ) => {
75+ const routes = [ "/" , ...flattenedPages . map ( ( page ) => page . route ) ] ;
76+ const today = new Date ( ) ;
77+ const formattedDate = `${ today . getFullYear ( ) } -${ String ( today . getMonth ( ) + 1 ) . padStart ( 2 , "0" ) } -${ String ( today . getDate ( ) ) . padStart ( 2 , "0" ) } ` ;
78+
79+ const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
80+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
81+ ${ routes
82+ . map (
83+ ( route ) => ` <url>
84+ <loc>https://typst-jp.github.io${ route } </loc>
85+ <lastmod>${ formattedDate } </lastmod>
86+ </url>` ,
87+ )
88+ . join ( "\n" ) }
89+ </urlset>
90+ ` ;
91+
92+ return c . text ( sitemap , 200 , {
93+ "Content-Type" : "application/xml" ,
94+ } ) ;
95+ } ) ;
96+
97+ app . get ( "/robots.txt" , ( c ) => {
98+ const robotsTxt = `User-agent: *
99+ Allow: /
100+
101+ Sitemap: https://typst-jp.github.io/sitemap.xml
102+ ` ;
103+
104+ return c . text ( robotsTxt , 200 , {
105+ "Content-Type" : "text/plain" ,
106+ } ) ;
107+ } ) ;
108+
74109export default app ;
You can’t perform that action at this time.
0 commit comments