diff --git a/dev/rss.js b/dev/rss.js deleted file mode 100644 index 2f9924f7a..000000000 --- a/dev/rss.js +++ /dev/null @@ -1,82 +0,0 @@ -const {Feed} = require('feed'); -const fs = require('fs'); -const path = require('path'); - -const loadChangelog = () => { - const changelogPath = path.join( - __dirname, - '..', - 'docs', - 'technical-changelog.mdx' - ); - return fs.readFileSync(changelogPath, 'utf8'); -}; - -const extractRSSComments = content => { - const regex = /\{\/\*\s*RSS=(.*?)\s*\*\/}/g; - const matches = []; - let match; - - while ((match = regex.exec(content)) !== null) { - matches.push(JSON.parse(match[1].trim())); - } - - return matches; -}; - -const generateRssFeed = () => { - const baseURL = 'https://sourcegraph.com'; - const siteURL = 'https://sourcegraph.com/docs'; - const date = new Date(); - - const feed = new Feed({ - title: 'Sourcegraph RSS', - description: 'RSS feed for Sourcegraph', - id: siteURL, - link: baseURL, - language: 'en', - image: `${siteURL}/sourcegraph-mark.png`, - favicon: `${siteURL}/sourcegraph-mark.png`, - copyright: `All rights reserved ${date.getFullYear()}, Sourcegraph`, - updated: date, - generator: 'Sourcegraph RSS Feed', - feedLinks: { - rss2: `${siteURL}/technical-changelog.rss` - }, - author: { - name: 'Sourcegraph', - email: 'hi@sourcegraph.com', - link: 'https://sourcegraph.com' - } - }); - - const changelog = loadChangelog(); - const rssComments = extractRSSComments(changelog); - - // the rss comments have the structure: {/* RSS={"version":"vX.Y.Z", "releasedAt": "" */} - for (let idx = 0; idx < rssComments.length; idx++) { - const comment = rssComments[idx]; - if (!comment.version || !comment.releasedAt) { - continue; - } - const tag = comment.version.replace('v', ''); - const versionDocLink = `${siteURL}/technical-changelog#${comment.version.replaceAll( - '.', - '' - )}`; - feed.addItem({ - title: `Sourcegraph ${tag}`, - id: comment.version, - link: versionDocLink, - description: `Sourcegraph ${tag} is now available! Note: we've updated our versioning conventions. Please see our releases page for more information.`, - date: new Date(comment.releasedAt) - }); - } - - fs.writeFileSync( - path.join(__dirname, '../public/technical-changelog.rss'), - feed.rss2() - ); -}; - -module.exports = {generateRssFeed}; diff --git a/next.config.js b/next.config.js index fb2eb2e2e..ba85bf759 100644 --- a/next.config.js +++ b/next.config.js @@ -1,5 +1,4 @@ const {withContentlayer} = require('next-contentlayer'); -const {generateRssFeed} = require('./dev/rss'); const {execSync} = require('child_process'); /** @type {import('next').NextConfig} */ @@ -24,6 +23,5 @@ module.exports = async () => { execSync('node dev/check-links.mjs', {stdio: 'inherit'}); execSync('node dev/check-filenames.mjs', {stdio: 'inherit'}); execSync('node dev/check-images.mjs', {stdio: 'inherit'}); - await generateRssFeed(); return withContentlayer(nextConfig); }; diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 8edafcf37..0b45f028b 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,5 +1,6 @@ import {Providers} from '@/app/providers'; import {Layout} from '@/components/Layout'; +import {TECHNICAL_CHANGELOG_RSS_URL} from '@/data/constants'; import {GoogleAnalytics} from '@next/third-parties/google'; import clsx from 'clsx'; import config from 'docs.config'; @@ -81,7 +82,7 @@ export default function RootLayout({children}: {children: React.ReactNode}) { rel="alternate" type="application/rss+xml" title="RSS Feed for Sourcegraph" - href="/technical-changelog.rss" + href={TECHNICAL_CHANGELOG_RSS_URL} />