diff options
author | terminaldweller <thabogre@gmail.com> | 2022-03-04 21:59:05 +0000 |
---|---|---|
committer | terminaldweller <thabogre@gmail.com> | 2022-03-04 21:59:05 +0000 |
commit | 75e5102ffd532a50604f6a95864fa6a13c32c235 (patch) | |
tree | a7cca87654fcc55ec0f8f92bc451de8f46b6dc33 | |
parent | added helmet (diff) | |
download | blog-75e5102ffd532a50604f6a95864fa6a13c32c235.tar.gz blog-75e5102ffd532a50604f6a95864fa6a13c32c235.zip |
rss, WIP
Diffstat (limited to '')
-rwxr-xr-x | server.js | 19 | ||||
-rw-r--r-- | views/index.ejs | 4 | ||||
-rw-r--r-- | views/rss_feed.pug | 21 |
3 files changed, 36 insertions, 8 deletions
@@ -33,6 +33,10 @@ app.engine("ejs", require("ejs").__express); app.use(helmet()); app.use(morgan("combined")); +async function enumerateDir() { + return await fs.readdirSync(path.join(__dirname, "mds")); +} + function renderAndSend(req, res) { try { let viewPath; @@ -90,10 +94,13 @@ app.get("/robots.txt", (req, res) => { res.send(robots_txt); }); -// app.get("/rss/feed", (req, res) => { -// let html = pug.renderFile("./views/rss_feed.pug", merge(options, localls)); -// res.send(html); -// }); +app.get("/rss/feed", (req, res) => { + const compiledFunction = pug.compileFile("./views/rss_feed.pug"); + const files = fs.readdirSync(path.join(__dirname, "mds")); + for (const file of files) { + res.send(compiledFunction(file)); + } +}); app.get("/$", (req, res) => { renderAndSend(req, res); @@ -106,10 +113,6 @@ app.get("/mds/:mdname$", (req, res) => { renderAndSend(req, res); }); -async function enumerateDir() { - return await fs.readdirSync(path.join(__dirname, "mds")); -} - app.use(sitemap(enumerateDir, "https://blog.terminaldweller.com")); app.use((req, res) => { diff --git a/views/index.ejs b/views/index.ejs index 4679e4a..529a5ed 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -5,6 +5,8 @@ <meta name="viewport" content="width=device-width"> <title>Blog</title> <link rel="stylesheet" href="/master.css" type="text/css" media="screen" title="no title" charset="utf-8"> + <link rel="alternate" type="application/rss+xml" title="RSS" href="/rss/feed"> + <!-- <link rel="alternate" type="application/atom+xml" title="RSS" href="/rss/feed"> --> </head> <body> <script>0</script> @@ -15,6 +17,8 @@ <br/> <a href="/archive" class="left-footer">Archive</a> <a href="/about" class="right-footer">About</a> + <a class="right-footer">   </a> + <a href="/rss/feed" class="right-footer">RSS</a> </div> </body> </html> diff --git a/views/rss_feed.pug b/views/rss_feed.pug new file mode 100644 index 0000000..9bdd9bd --- /dev/null +++ b/views/rss_feed.pug @@ -0,0 +1,21 @@ +doctype xml +rss(version='2.0', xmlns:atom='<a href="http://www.w3.org/2005/Atom" rel="nofollow">http://www.w3.org/2005/Atom</a>') + channel + title DevSmash + link <a href="http://devsmash.com" rel="nofollow">http://devsmash.com</a> + atom:link(href='<a href="http://devsmash.com/feed/rss" rel="nofollow">http://devsmash.com/feed/rss</a>', rel='self', type='application/rss+xml') + description Developers talking about stuff that developers like to talk about. + language en-US + if posts.length + lastBuildDate= new Date(posts[0].publishedAt).toUTCString() + each post in posts + item + title= post.title + link <a href="http://devsmash.com/blog/#{post.slug}" rel="nofollow">http://devsmash.com/blog/#{post.slug}</a> + description + | <![CDATA[ + | !{post.teaser} + p: a(href='<a href="http://devsmash.com/blog/#{post.slug}')!=" rel="nofollow">http://devsmash.com/blog/#{post.slug}')!=</a> 'Read more »' + | ]]> + pubDate= new Date(post.publishedAt).toUTCString() + guid(isPermaLink='false') <a href="http://devsmash.com/blog/#{post.slug}" |