astro-accelerator 5.9.15 → 5.9.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/src/pages/rss.xml.ts +113 -0
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "5.9.
|
|
2
|
+
"version": "5.9.16",
|
|
3
3
|
"author": "Steve Fenton",
|
|
4
4
|
"name": "astro-accelerator",
|
|
5
5
|
"description": "A super-lightweight, accessible, SEO-friendly starter project for Astro",
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
"src/pages/404.md",
|
|
62
62
|
"src/pages/index.md",
|
|
63
63
|
"src/pages/search.md",
|
|
64
|
+
"src/pages/rss.xml.ts",
|
|
64
65
|
"src/pages/articles/*.astro",
|
|
65
66
|
"src/pages/articles/*.ts",
|
|
66
67
|
"src/pages/authors/**/*.astro",
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/** @format */
|
|
2
|
+
|
|
3
|
+
// warning: This file is overwritten by Astro Accelerator
|
|
4
|
+
|
|
5
|
+
// Generates an ATOM feed across the whole site with full content
|
|
6
|
+
import { SITE } from '@config';
|
|
7
|
+
import {
|
|
8
|
+
Accelerator,
|
|
9
|
+
PostFiltering,
|
|
10
|
+
PostOrdering,
|
|
11
|
+
} from 'astro-accelerator-utils';
|
|
12
|
+
import type { MarkdownInstance } from 'astro-accelerator-utils/types/Astro';
|
|
13
|
+
|
|
14
|
+
type Frontmatter = MarkdownInstance['frontmatter'];
|
|
15
|
+
|
|
16
|
+
async function getData() {
|
|
17
|
+
//@ts-ignore
|
|
18
|
+
const allArticles = import.meta.glob(['./**/*.md', './**/*.mdx']);
|
|
19
|
+
|
|
20
|
+
const accelerator = new Accelerator(SITE);
|
|
21
|
+
const stats = new accelerator.statistics('pages/articles/feed.xml');
|
|
22
|
+
stats.start();
|
|
23
|
+
|
|
24
|
+
let articles: MarkdownInstance[] = [];
|
|
25
|
+
const authors = accelerator.posts.all().filter(PostFiltering.isAuthor);
|
|
26
|
+
const contentItems: { [index: string]: string } = {};
|
|
27
|
+
|
|
28
|
+
for (const path in allArticles) {
|
|
29
|
+
const article: any = await allArticles[path]();
|
|
30
|
+
|
|
31
|
+
const filtered = [article]
|
|
32
|
+
.filter(PostFiltering.isListable)
|
|
33
|
+
.filter(PostFiltering.notAuthor)
|
|
34
|
+
.filter(PostFiltering.notSearch);
|
|
35
|
+
|
|
36
|
+
if (filtered.length === 0) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (typeof article.compiledContent !== 'function') {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const content = await article.compiledContent();
|
|
45
|
+
contentItems[article.url] = content;
|
|
46
|
+
|
|
47
|
+
article.frontmatter.title = await accelerator.markdown.getTextFrom(
|
|
48
|
+
article.frontmatter?.title
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
articles.push({
|
|
52
|
+
url: article.url,
|
|
53
|
+
frontmatter: article.frontmatter,
|
|
54
|
+
} as MarkdownInstance);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function getAuthorName(frontmatter: Frontmatter): string {
|
|
58
|
+
if (frontmatter.authors && frontmatter.authors.length > 0) {
|
|
59
|
+
const author = authors.filter(
|
|
60
|
+
(a) => a.frontmatter.id == frontmatter.authors?.[0]
|
|
61
|
+
)[0];
|
|
62
|
+
|
|
63
|
+
if (author?.frontmatter?.title) {
|
|
64
|
+
return author.frontmatter.title + ', Octopus Deploy';
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return 'Octopus Deploy';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const limit = SITE.rssLimit ?? 20;
|
|
72
|
+
const items = articles
|
|
73
|
+
.sort(PostOrdering.sortByModDateDesc)
|
|
74
|
+
.slice(0, limit)
|
|
75
|
+
.map(
|
|
76
|
+
(a) => `
|
|
77
|
+
<entry>
|
|
78
|
+
<title>${a.frontmatter.title ?? ''}</title>
|
|
79
|
+
<link href="${SITE.url + a.url}" />
|
|
80
|
+
<id>${SITE.url + accelerator.urlFormatter.formatAddress(a.url)}</id>
|
|
81
|
+
<published>${a.frontmatter.pubDate}</published>
|
|
82
|
+
<updated>${a.frontmatter.modDate ?? a.frontmatter.pubDate}</updated>
|
|
83
|
+
<summary>${a.frontmatter.description ?? ''}</summary>
|
|
84
|
+
<author>
|
|
85
|
+
<name>${getAuthorName(a.frontmatter)}</name>
|
|
86
|
+
</author>
|
|
87
|
+
<content type="html"><![CDATA[${contentItems[a.url] ?? ''}]]></content>
|
|
88
|
+
</entry>`
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
stats.stop();
|
|
92
|
+
|
|
93
|
+
return new Response(
|
|
94
|
+
`<?xml version="1.0" encoding="utf-8"?>
|
|
95
|
+
<feed xmlns="http://www.w3.org/2005/Atom">
|
|
96
|
+
<title>${SITE.title}</title>
|
|
97
|
+
<subtitle>${SITE.description}</subtitle>
|
|
98
|
+
<link href="${SITE.url}${SITE.feedUrl}" rel="self" />
|
|
99
|
+
<link href="${SITE.url}" />
|
|
100
|
+
<id>${SITE.url}${SITE.feedUrl}</id>
|
|
101
|
+
<updated>${articles[0].frontmatter.pubDate}</updated>
|
|
102
|
+
${items.join('')}
|
|
103
|
+
</feed>`,
|
|
104
|
+
{
|
|
105
|
+
status: 200,
|
|
106
|
+
headers: {
|
|
107
|
+
'Content-Type': 'application/xml',
|
|
108
|
+
},
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export const GET = getData;
|