Skip to content

Commit fe06dde

Browse files
authored
fix: a quick changelog fix (#7987)
1 parent a237b4e commit fe06dde

1 file changed

Lines changed: 18 additions & 23 deletions

File tree

scripts/generate-changelog.js

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,32 @@
11
/// @ts-check
2-
import fs from 'node:fs';
2+
import * as fs from 'node:fs';
33
import path from 'node:path';
44
import { fileURLToPath } from 'node:url';
5-
import matter from 'gray-matter';
5+
import { XMLParser } from 'fast-xml-parser';
66

77
const __dirname = fileURLToPath(new URL('.', import.meta.url));
88

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 [];
2014
}
2115

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+
});
2522

26-
if (data.title && data.date) {
27-
const pathname = file
28-
.replace('.mdx', '')
29-
.replace('(posts)/', '')
30-
.replace(/\/page$/, '');
23+
const changelogRecords = [];
3124

25+
for (const data of feed) {
26+
if (data.title && data.pubDate && data.link) {
3227
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,
3530
title: data.title,
3631
description: data.description || '',
3732
});

0 commit comments

Comments
 (0)