-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
384aeee
commit c110afb
Showing
4 changed files
with
85 additions
and
10 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 |
---|---|---|
|
@@ -17,7 +17,6 @@ for (const blog of blogs) { | |
blog.title = (blog.title || "").trim(); | ||
blog.desc = (blog.desc || "").trim(); | ||
if (!blog.url) continue; | ||
if (blog.title && blog.title === blog.desc) console.log(blog.title); | ||
if ( | ||
3 > | ||
0 + | ||
|
@@ -90,6 +89,7 @@ const about = ` | |
<p><a href="/">blogs.hn</a> is a directory of tech sites, primarily sourced from <a href="https://news.ycombinator.com">HackerNews</a>.</p> | ||
<p>To submit/update a blog, <a href="https://github.com/surprisetalk/blogs.hn/blob/main/blogs.json">edit blogs.json in a pull-request</a>.</p> | ||
<p>If you like sites with RSS feeds, consider checking out <a href="https://ooh.directory">ooh.directory</a>. If you don't have an RSS reader, I highly recommend <a href="https://reederapp.com">Reeder 5</a>.</p> | ||
<p>You can import all the RSS feeds via <a href="/blogs.hn.opml" download>this OPML file</a>.</p> | ||
<p>And if you aren't already, <em>you should</em> <a href="https://www.benkuhn.net/writing/">write things on the internet</a>. All you need is <a href="https://github.com/surprisetalk/worstpress">worstpress</a> and some markdown files! You can <a href="mailto:[email protected]">email me</a> if you need help getting started.</p> | ||
<p>Every blog is a window into a skull. Don't be afraid to ask questions and kindle friendships! Remember to be kind, courteous, and succinct.</p> | ||
<p>Thanks for stopping by.</p> | ||
|
@@ -102,3 +102,30 @@ fs.writeFileSync( | |
"./dist/about.html", | ||
template.replace("{{body}}", `<main id="about">${about}</main>`) | ||
); | ||
|
||
const escxml = unsafe => { | ||
return unsafe.replace(/[<>&'"]/g, (c) => { | ||
switch (c) { | ||
case '<': return '<'; | ||
case '>': return '>'; | ||
case '&': return '&'; | ||
case '\'': return '''; | ||
case '"': return '"'; | ||
default: return c; | ||
} | ||
}); | ||
}; | ||
fs.writeFileSync( | ||
"./dist/blogs.hn.opml", | ||
`<?xml version="1.0" encoding="UTF-8"?> | ||
<opml version="2.0"> | ||
<head> | ||
<title>blogs.hn</title> | ||
</head> | ||
<body> | ||
${blogs.filter(blog => blog.title && blog.feed && blog.url).map(blog => `<outline type="rss" text="${escxml(blog.title.trim())}" title="${escxml(blog.title.trim())}" htmlUrl="${blog.url.trim()}" xmlUrl="${blog.feed.trim()}" />`.replace(/\s+/gi, " ")).join('\n')} | ||
</body> | ||
</opml>`, | ||
"utf-8" | ||
); | ||
|
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,50 @@ | ||
const fetch = require("node-fetch"); | ||
const xml2js = require("xml2js"); | ||
|
||
process.stdin.setEncoding('utf8'); | ||
|
||
let input = ''; | ||
process.stdin.on('data', chunk => input += chunk); | ||
|
||
process.stdin.on('end', async () => { | ||
try { | ||
const feeds = JSON.parse(input) | ||
.map(x => x.feed) | ||
.filter(x => x) | ||
.sort(() => Math.random() - 0.5) | ||
.slice(0, 1); | ||
|
||
const results = await Promise.all(feeds.map(async (url) => { | ||
try { | ||
console.log(url); | ||
const response = await fetch(url); | ||
const text = await response.text(); | ||
const parser = new xml2js.Parser(); | ||
const xml = await parser.parseStringPromise(text); | ||
|
||
const items = xml.rss ? xml.rss.channel[0].item : xml.feed.entry; | ||
return items.map(item => { | ||
let obj = {}; | ||
for (let key in item) { | ||
obj[key] = item[key][0]; | ||
} | ||
return obj; | ||
}); | ||
} catch (error) { | ||
return []; | ||
} | ||
})); | ||
|
||
console.log(results?.[0]); | ||
|
||
const output = results | ||
.flatMap(x => x) | ||
.filter(x => x.id || x.guid) | ||
.map(x => `${x.id || x.guid}\t${x.link}`) | ||
.join('\n'); | ||
|
||
console.log(output); | ||
} catch (error) { | ||
console.error("Error parsing input or processing feeds:", error); | ||
} | ||
}); |
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