Skip to content

Commit a4298af

Browse files
committed
ADD: sitemap.xml
1 parent 68b1c27 commit a4298af

File tree

5 files changed

+77
-7
lines changed

5 files changed

+77
-7
lines changed

TODO.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# To Do
22

3-
- [ ] sitemap.xml
4-
- [ ] search.html
53
- [ ] copy to clipboard for variations
4+
- [ ] search.html
65
- [ ] test button for variations
76
- [ ] comments via utteranc.es
87
- [ ] homepage: search

app/routes/library.tags[.]html.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { json, type MetaFunction, SerializeFrom } from "@remix-run/node";
2-
import { useLoaderData, useSearchParams } from "@remix-run/react";
2+
import { Link as RemixLink, useLoaderData, useSearchParams } from "@remix-run/react";
33
import { Container } from "react-bootstrap";
44
import { Footer } from "~/components/Footer";
55

@@ -47,7 +47,7 @@ function TagRow(tag:string, currentTag: string, entries: SerializeFrom<TagEntry>
4747
<ul className="mt-1">
4848
{entries?.map((entry) => (
4949
<li key={entry.url}>
50-
<a href={entry.url}>{entry.title}</a>
50+
<RemixLink to={entry.url}>{entry.title}</RemixLink>
5151
</li>
5252
))}
5353
</ul>

app/routes/search[.]html.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import type { MetaFunction } from "@remix-run/node";
2-
import { Welcome } from "~/components/Welcome/Welcome";
3-
import { ColorSchemeToggle } from "~/components/ColorSchemeToggle/ColorSchemeToggle";
42
import { HeaderSearch } from "~/components/HeaderSearch/HeaderSearch";
5-
import { Badge, Container, Table } from 'react-bootstrap';
3+
import { Container } from 'react-bootstrap';
64
import { Footer } from "~/components/Footer";
75

86
export const meta: MetaFunction = () => {

app/routes/sitemap[.]xml.tsx

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { getAll, initialize } from "~/components/Library";
2+
3+
function urlLine(url:string) {
4+
return `\t<url><loc>https://www.regex.zone${url}</loc></url>`
5+
}
6+
7+
export async function loader() {
8+
9+
const lines:string[] = [];
10+
11+
lines.push("<?xml version='1.0' encoding='UTF-8'?>");
12+
lines.push('<?xml-stylesheet type="text/xsl" href="/sitemap.xslt" ?>');
13+
lines.push('<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9">');
14+
lines.push(urlLine('/'));
15+
lines.push(urlLine('/library/'));
16+
lines.push(urlLine('/library/tags.html'));
17+
lines.push(urlLine('/search.html'));
18+
19+
initialize();
20+
for (const entry of getAll()) {
21+
lines.push(urlLine(`/library/${entry.handle}/`));
22+
}
23+
24+
lines.push('</urlset>')
25+
26+
return new Response(lines.join('\n'), {
27+
headers: {
28+
"Content-Type": "text/xml; charset=utf-8",
29+
},
30+
});
31+
}

public/sitemap.xslt

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xsl:stylesheet
3+
version="3.0"
4+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5+
xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
6+
>
7+
<xsl:output method="html" indent="yes" encoding="UTF-8"/>
8+
<xsl:template match="/">
9+
<xsl:message>Powered by <a href="https://www.sitemap.style/">Sitemap Style</a></xsl:message>
10+
11+
12+
<!-- get the hostname from the first url/loc -->
13+
<xsl:variable name="hostname" select="substring-before(substring-after(/sitemap:urlset/sitemap:url[1]/sitemap:loc, '://'), '/')" />
14+
15+
<html>
16+
<head>
17+
<meta name="viewport" content="width=device-width, initial-scale=1" />
18+
<meta name="referrer" content="unsafe-url" />
19+
<title>Sitemap for <xsl:value-of select="$hostname"/></title>
20+
<link rel="stylesheet" href="https://www.sitemap.style/css/pico.classless.min.css" />
21+
</head>
22+
<body>
23+
<main class="container">
24+
<h1>Pages on <xsl:value-of select="$hostname"/></h1>
25+
<ul>
26+
<xsl:for-each select="sitemap:urlset/sitemap:url">
27+
<xsl:variable name="sitemap_loc"><xsl:value-of select="sitemap:loc"/></xsl:variable>
28+
<xsl:variable name="sitemap_lastmod"><xsl:value-of select="sitemap:lastmod"/></xsl:variable>
29+
<li>
30+
<a href="{$sitemap_loc}"><xsl:value-of select="sitemap:loc" /></a>
31+
<xsl:if test="$sitemap_lastmod!=''">
32+
(<xsl:value-of select="sitemap:lastmod" />)
33+
</xsl:if>
34+
</li>
35+
</xsl:for-each>
36+
</ul>
37+
<p><xsl:value-of select="count(sitemap:urlset/sitemap:url)"/> pages</p>
38+
</main>
39+
</body>
40+
</html>
41+
</xsl:template>
42+
</xsl:stylesheet>

0 commit comments

Comments
 (0)