-
-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into footerAesthetics
- Loading branch information
Showing
6 changed files
with
394 additions
and
51 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,45 @@ | ||
language: "en-US" | ||
reviews: | ||
profile: "assertive" | ||
request_changes_workflow: false | ||
high_level_summary: true | ||
poem: true | ||
review_status: true | ||
auto_review: | ||
enabled: true | ||
tools: | ||
spellcheck: | ||
enabled: true | ||
markdownlint: | ||
enabled: true | ||
biome: | ||
enabled: true | ||
github-checks: | ||
enabled: true | ||
timeout_ms: 180000 | ||
languagetool: | ||
enabled: true | ||
enabled_only: false | ||
level: default | ||
hadolint: | ||
enabled: true | ||
yamllint: | ||
enabled: true | ||
gitleaks: | ||
enabled: true | ||
eslint: | ||
enabled: true | ||
actionlint: | ||
enabled: true | ||
semgrep: | ||
enabled: true | ||
chat: | ||
auto_reply: true | ||
knowledge_base: | ||
opt_out: false | ||
learnings: | ||
scope: "local" | ||
issues: | ||
scope: "local" | ||
pull_requests: | ||
scope: "local" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
const fs = require('fs') | ||
const fs = require('fs').promises | ||
const json2xml = require('jgexml/json2xml') | ||
|
||
function getAllPosts() { | ||
return require('../config/posts.json') | ||
return require('../config/posts.json'); | ||
} | ||
|
||
function clean(s) { | ||
|
@@ -15,61 +15,89 @@ function clean(s) { | |
return s | ||
} | ||
|
||
module.exports = function rssFeed(type, title, desc, outputPath) { | ||
module.exports = async function rssFeed(type, title, desc, outputPath) { | ||
try { | ||
|
||
const posts = getAllPosts()[`${type}`] | ||
.sort((i1, i2) => { | ||
const i1Date = new Date(i1.date) | ||
const i2Date = new Date(i2.date) | ||
let posts = getAllPosts()[`${type}`] | ||
const missingDatePosts = posts.filter(post => !post.date); | ||
posts = posts.filter(post => post.date); | ||
posts.sort((i1, i2) => { | ||
const i1Date = new Date(i1.date); | ||
const i2Date = new Date(i2.date); | ||
if (i1.featured && !i2.featured) return -1; | ||
if (!i1.featured && i2.featured) return 1; | ||
return i2Date - i1Date; | ||
}); | ||
|
||
if (i1.featured && !i2.featured) return -1 | ||
if (!i1.featured && i2.featured) return 1 | ||
return i2Date - i1Date | ||
}) | ||
if (missingDatePosts.length > 0) { | ||
throw new Error(`Missing date in posts: ${missingDatePosts.map(p => p.title || p.slug).join(', ')}`); | ||
} | ||
|
||
const base = 'https://www.asyncapi.com' | ||
const tracking = '?utm_source=rss'; | ||
|
||
const feed = {} | ||
const rss = {} | ||
rss['@version'] = '2.0' | ||
rss["@xmlns:atom"] = 'http://www.w3.org/2005/Atom' | ||
rss.channel = {} | ||
rss.channel.title = title | ||
rss.channel.link = `${base}/${outputPath}` | ||
rss.channel["atom:link"] = {} | ||
rss.channel["atom:link"]["@rel"] = 'self' | ||
rss.channel["atom:link"]["@href"] = rss.channel.link | ||
rss.channel["atom:link"]["@type"] = 'application/rss+xml' | ||
rss.channel.description = desc | ||
rss.channel.language = 'en-gb'; | ||
rss.channel.copyright = 'Made with :love: by the AsyncAPI Initiative.'; | ||
rss.channel.webMaster = '[email protected] (AsyncAPI Initiative)' | ||
rss.channel.pubDate = new Date().toUTCString() | ||
rss.channel.generator = 'next.js' | ||
rss.channel.item = [] | ||
|
||
const base = 'https://www.asyncapi.com' | ||
const tracking = '?utm_source=rss'; | ||
const invalidPosts = posts.filter(post => | ||
!post.title || !post.slug || !post.excerpt || !post.date | ||
); | ||
|
||
const feed = {} | ||
const rss = {} | ||
rss['@version'] = '2.0' | ||
rss["@xmlns:atom"] = 'http://www.w3.org/2005/Atom' | ||
rss.channel = {} | ||
rss.channel.title = title | ||
rss.channel.link = `${base}/${outputPath}` | ||
rss.channel["atom:link"] = {} | ||
rss.channel["atom:link"]["@rel"] = 'self' | ||
rss.channel["atom:link"]["@href"] = rss.channel.link | ||
rss.channel["atom:link"]["@type"] = 'application/rss+xml' | ||
rss.channel.description = desc | ||
rss.channel.language = 'en-gb'; | ||
rss.channel.copyright = 'Made with :love: by the AsyncAPI Initiative.'; | ||
rss.channel.webMaster = '[email protected] (AsyncAPI Initiative)' | ||
rss.channel.pubDate = new Date().toUTCString() | ||
rss.channel.generator = 'next.js' | ||
rss.channel.item = [] | ||
if (invalidPosts.length > 0) { | ||
throw new Error(`Missing required fields in posts: ${invalidPosts.map(p => p.title || p.slug).join(', ')}`); | ||
} | ||
|
||
for (let post of posts) { | ||
const link = `${base}${post.slug}${tracking}`; | ||
const item = { title: post.title, description: clean(post.excerpt), link, category: type, guid: { '@isPermaLink': true, '': link }, pubDate: new Date(post.date).toUTCString() } | ||
if (post.cover) { | ||
const enclosure = {}; | ||
enclosure["@url"] = base+post.cover; | ||
enclosure["@length"] = 15026; // dummy value, anything works | ||
enclosure["@type"] = 'image/jpeg'; | ||
if (typeof enclosure["@url"] === 'string') { | ||
let tmp = enclosure["@url"].toLowerCase(); | ||
if (tmp.indexOf('.png')>=0) enclosure["@type"] = 'image/png'; | ||
if (tmp.indexOf('.svg')>=0) enclosure["@type"] = 'image/svg+xml'; | ||
if (tmp.indexOf('.webp')>=0) enclosure["@type"] = 'image/webp'; | ||
for (let post of posts) { | ||
const link = `${base}${post.slug}${tracking}`; | ||
const { title, excerpt, date } = post; | ||
const pubDate = new Date(date).toUTCString(); | ||
const description = clean(excerpt); | ||
const guid = { '@isPermaLink': true, '': link }; | ||
const item = { | ||
title, | ||
description, | ||
link, | ||
category: type, | ||
guid, | ||
pubDate | ||
}; | ||
if (post.cover) { | ||
const enclosure = {}; | ||
enclosure["@url"] = base + post.cover; | ||
enclosure["@length"] = 15026; // dummy value, anything works | ||
enclosure["@type"] = 'image/jpeg'; | ||
if (typeof enclosure["@url"] === 'string') { | ||
let tmp = enclosure["@url"].toLowerCase(); | ||
if (tmp.indexOf('.png') >= 0) enclosure["@type"] = 'image/png'; | ||
if (tmp.indexOf('.svg') >= 0) enclosure["@type"] = 'image/svg+xml'; | ||
if (tmp.indexOf('.webp') >= 0) enclosure["@type"] = 'image/webp'; | ||
} | ||
item.enclosure = enclosure; | ||
} | ||
item.enclosure = enclosure; | ||
rss.channel.item.push(item) | ||
} | ||
rss.channel.item.push(item) | ||
} | ||
|
||
feed.rss = rss | ||
feed.rss = rss | ||
|
||
const xml = json2xml.getXml(feed,'@','',2) | ||
fs.writeFileSync(`./public/${outputPath}`, xml, 'utf8') | ||
const xml = json2xml.getXml(feed, '@', '', 2); | ||
await fs.writeFile(`./public/${outputPath}`, xml, 'utf8'); | ||
} catch (err) { | ||
throw new Error(`Failed to generate RSS feed: ${err.message}`); | ||
} | ||
}; |
Oops, something went wrong.