-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sitemap depends on internal sapper realization, which is bad, but works till we need to add another langs
- Loading branch information
Showing
4 changed files
with
69 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import posts from './blog/_posts.js'; | ||
|
||
const sortedPosts = posts.sort( (a, b) => {return new Date(a.data.date.split('.').reverse().toString())<new Date(b.data.date.split('.').reverse().toString())? 1 : -1} ) | ||
const render = (posts) => `<?xml version="1.0" encoding="UTF-8" ?> | ||
<rss version="2.0"> | ||
<channel> | ||
<title>mailcheck.co</title> | ||
<link>https://www.mailcheck.co/blog</link> | ||
<description>Posts from Mailcheck.co</description> | ||
${posts.map(post => ` | ||
<item> | ||
<title>${post.data.title}</title> | ||
<link>https://www.mailcheck.co/blog/${post.data.slug}</link> | ||
<description><![CDATA[${post.data.snippet}]]></description> | ||
<pubDate>${new Date(post.data.date.split('.').reverse().toString()).toISOString()}</pubDate> | ||
</item> | ||
`).join('')} | ||
</channel> | ||
</rss>`; | ||
|
||
export function get(req, res, next) { | ||
|
||
res.setHeader('Cache-Control', `max-age=0, s-max-age=${600}`); // 10 minutes | ||
res.setHeader('Content-Type', 'application/rss+xml'); | ||
const feed = render(sortedPosts); | ||
res.end(feed); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {routes} from '@sapper/internal/manifest-client.mjs'; | ||
|
||
const render = (pages, categories, posts) => `<?xml version="1.0" encoding="UTF-8" ?> | ||
<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 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> | ||
${pages.map(page => ` | ||
<url><loc>https://www.mailcheck.co/${page}</loc></url> | ||
`).join('')} | ||
${categories.map(cat => ` | ||
<url><loc>https://www.mailcheck.co/blog/c/${cat}/</loc></url> | ||
`).join('')} | ||
${posts.map(post => ` | ||
<url><loc>https://www.mailcheck.co/${post}/</loc></url> | ||
`).join('')} | ||
</urlset> | ||
`; | ||
|
||
export function get(req, res, next) { | ||
|
||
res.setHeader('Cache-Control', `max-age=0, s-max-age=${600}`); // 10 minutes | ||
res.setHeader('Content-Type', 'application/rss+xml'); | ||
|
||
let data = [] | ||
routes.forEach(el => { | ||
data.push( el.pattern.source.toString().replace(/\\/g, '').split('/').filter(el => /[a-zA-Z-]/.exec(el)).join('/')) | ||
}) | ||
data = [...new Set(data)] | ||
|
||
const pages = data.filter(url=>url.search('/')===-1); | ||
const posts = data.filter(url=>url.search('/')>0); | ||
|
||
|
||
const feed = render(pages, [], posts); | ||
res.end(feed); | ||
} |
This file was deleted.
Oops, something went wrong.