diff options
| author | Kevin J Hoerr <kjhoerr@protonmail.com> | 2023-12-24 08:13:33 +0000 |
|---|---|---|
| committer | Kevin J Hoerr <kjhoerr@protonmail.com> | 2023-12-24 08:13:33 +0000 |
| commit | 1c4c99f0c19f19424e3aee04e868c38333164dd9 (patch) | |
| tree | 783970ddbd3d1f696493a8b66d9cff6aed533b68 | |
| parent | 3bc3700152504ac0ff4f9a42a45ab59cde2e189d (diff) | |
| download | submelon.dev-1c4c99f0c19f19424e3aee04e868c38333164dd9.tar.gz submelon.dev-1c4c99f0c19f19424e3aee04e868c38333164dd9.tar.bz2 submelon.dev-1c4c99f0c19f19424e3aee04e868c38333164dd9.zip | |
Generate sitemap.xml, robots.txt
| -rw-r--r-- | config.json | 1 | ||||
| -rw-r--r-- | public/robots.txt | 3 | ||||
| -rw-r--r-- | public/sitemap.xml | 18 | ||||
| -rw-r--r-- | public/sitemap/index.html | 0 | ||||
| -rw-r--r-- | src/config.ts | 6 | ||||
| -rw-r--r-- | src/pages/robots.njk | 7 | ||||
| -rw-r--r-- | src/pages/sitemap.njk | 15 | ||||
| -rw-r--r-- | src/util/timestamp.ts | 7 |
8 files changed, 56 insertions, 1 deletions
diff --git a/config.json b/config.json index 1b4b12b..1d53331 100644 --- a/config.json +++ b/config.json @@ -1,3 +1,4 @@ { + "url": "https://submelon.dev", "version": "1703404521" }
\ No newline at end of file diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..e41b9fd --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,3 @@ +User-agent: * +Allow: / +Sitemap: https://submelon.dev/sitemap.xml
\ No newline at end of file diff --git a/public/sitemap.xml b/public/sitemap.xml new file mode 100644 index 0000000..933afca --- /dev/null +++ b/public/sitemap.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> + + <url> + <loc>https://submelon.dev/404/</loc> + <lastmod>2023-12-24</lastmod> + <changefreq>monthly</changefreq> + <priority>0.8</priority> + </url> + + <url> + <loc>https://submelon.dev/</loc> + <lastmod>2023-12-24</lastmod> + <changefreq>monthly</changefreq> + <priority>0.8</priority> + </url> + +</urlset>
\ No newline at end of file diff --git a/public/sitemap/index.html b/public/sitemap/index.html new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/public/sitemap/index.html diff --git a/src/config.ts b/src/config.ts index 75ba2dd..c9f5ba0 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,4 +1,4 @@ -import { getTimestamp } from "./util/timestamp"; +import { formatDate, getTimestamp } from "./util/timestamp"; import BuildInfo from "../config.json"; // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -9,10 +9,14 @@ export default function (eleventyConfig: any) { }); // hook in configured build time for GH action to update + eleventyConfig.addGlobalData("site", () => BuildInfo); eleventyConfig.addGlobalData("buildTimeEncoded", () => { return getTimestamp(Number(BuildInfo.version)); }); + // add `date` filter + eleventyConfig.addFilter("formatDate", formatDate); + // ensure eleventy marks this config as watched, since it's typescript eleventyConfig.addWatchTarget("./src/config.ts"); diff --git a/src/pages/robots.njk b/src/pages/robots.njk new file mode 100644 index 0000000..efb8b84 --- /dev/null +++ b/src/pages/robots.njk @@ -0,0 +1,7 @@ +--- +eleventyExcludeFromCollections: true +permalink: /robots.txt +--- +User-agent: * +Allow: / +Sitemap: {{ site.url }}/sitemap.xml
\ No newline at end of file diff --git a/src/pages/sitemap.njk b/src/pages/sitemap.njk new file mode 100644 index 0000000..455c26b --- /dev/null +++ b/src/pages/sitemap.njk @@ -0,0 +1,15 @@ +--- +eleventyExcludeFromCollections: true +permalink: /sitemap.xml +--- +<?xml version="1.0" encoding="UTF-8"?> +<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> +{% for item in collections.all %} + <url> + <loc>{{ site.url }}{{ item.url }}</loc> + <lastmod>{{ item.date | formatDate }}</lastmod> + <changefreq>{{ item.data.sitemapChangefreq | default("monthly") }}</changefreq> + <priority>{{ item.data.sitemapPriority | default(0.8) }}</priority> + </url> +{% endfor %} +</urlset>
\ No newline at end of file diff --git a/src/util/timestamp.ts b/src/util/timestamp.ts index 01b78fb..39683cc 100644 --- a/src/util/timestamp.ts +++ b/src/util/timestamp.ts @@ -63,3 +63,10 @@ export function getTimestamp(seconds: number): string { return dateArr.map(encodeBase62).join(".") + "-0"; } + +/** + * Returns a date in the ISO-8601 format + */ +export function formatDate(date: Date): string { + return date.getUTCFullYear() + "-" + (date.getUTCMonth() + 1) + "-" + date.getUTCDate(); +} |
