|
1 | 1 | /// @ts-check |
2 | | -import fs from 'node:fs'; |
| 2 | +import * as fs from 'node:fs'; |
3 | 3 | import path from 'node:path'; |
4 | 4 | import { fileURLToPath } from 'node:url'; |
5 | | -import matter from 'gray-matter'; |
| 5 | +import { XMLParser } from 'fast-xml-parser'; |
6 | 6 |
|
7 | 7 | const __dirname = fileURLToPath(new URL('.', import.meta.url)); |
8 | 8 |
|
9 | | -const productUpdatesDirectory = path.join( |
10 | | - __dirname, |
11 | | - '../packages/web/docs/src/app/product-updates', |
12 | | -); |
13 | | - |
14 | | -const files = fs.globSync('**/*.mdx', { cwd: productUpdatesDirectory }); |
15 | | -const changelogRecords = []; |
16 | | - |
17 | | -for (const file of files) { |
18 | | - if (!file.endsWith('.mdx') || file.endsWith('index.mdx')) { |
19 | | - continue; |
| 9 | +const feedUrl = 'https://the-guild.dev/graphql/hive/feed.xml'; |
| 10 | +const feed = await fetch(feedUrl).then(async res => { |
| 11 | + if (res.status !== 200) { |
| 12 | + console.log('skip feed building; feed is unavailable.'); |
| 13 | + return []; |
20 | 14 | } |
21 | 15 |
|
22 | | - const filePath = path.join(productUpdatesDirectory, file); |
23 | | - const content = fs.readFileSync(filePath, 'utf-8'); |
24 | | - const { data } = matter(content); |
| 16 | + const parser = new XMLParser(); |
| 17 | + |
| 18 | + const body = await res.text(); |
| 19 | + const data = parser.parse(body); |
| 20 | + return data['rss']?.['channel']?.['item'] ?? []; |
| 21 | +}); |
25 | 22 |
|
26 | | - if (data.title && data.date) { |
27 | | - const pathname = file |
28 | | - .replace('.mdx', '') |
29 | | - .replace('(posts)/', '') |
30 | | - .replace(/\/page$/, ''); |
| 23 | +const changelogRecords = []; |
31 | 24 |
|
| 25 | +for (const data of feed) { |
| 26 | + if (data.title && data.pubDate && data.link) { |
32 | 27 | changelogRecords.push({ |
33 | | - date: new Date(data.date).toISOString().split('T')[0], |
34 | | - href: `https://the-guild.dev/graphql/hive/product-updates/${pathname}`, |
| 28 | + date: new Date(data.pubDate).toISOString().split('T')[0], |
| 29 | + href: data.link, |
35 | 30 | title: data.title, |
36 | 31 | description: data.description || '', |
37 | 32 | }); |
|
0 commit comments