-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.js
More file actions
78 lines (64 loc) · 1.97 KB
/
Copy pathparse.js
File metadata and controls
78 lines (64 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const Feed = require('feed').Feed;
const parse = require('node-html-parser').parse
const fs = require('fs')
const baseUrl = "http://localhost:3000" // process.env.BASE_URL;
const date = new Date()
const author = {
name: 'Paul Sweeney',
email: 'paul@sweeneyapps.com',
link: 'https://twitter.com/vphreak'
}
const feed = new Feed({
title: `Paul's blog`,
description: 'Welcome to my blog!',
id: baseUrl,
link: baseUrl,
language: 'en',
copyright: `All rights reserved ${date.getFullYear()}, Paul`,
updated: date,
generator: 'Next.js using Feed for Node.js',
feedLinks: {
rss2: `${baseUrl}/rss/feed.xml`,
json: `${baseUrl}/rss/feed.json`,
atom: `${baseUrl}/rss/atom.xml`
},
author
})
function addItem({title, description, content, url, rawDate}) {
feed.addItem({
title,
id: url,
link: url,
description,
content,
author: [author],
contributor: [author],
date: new Date(rawDate)
})
}
addItem({
title: "How to write a blog",
description: 'you will learn how to write a blog cleanly',
id: "1",
link: "https://localhost:3000/howtowriteblog",
rawDate: 'March 28, 2021',
content: `<h1> I'm the content here </h1>`,
})
const htmlfiles = fs.readdirSync(`${process.cwd()}/`, "utf-8")
const listOfHtmlFiles = htmlfiles.filter(filename => filename.endsWith(".html"))
listOfHtmlFiles.forEach((filename) => {
let htmlContent = fs.readFileSync(`${process.cwd()}/${filename}`, 'utf8');
const root = parse(htmlContent);
addItem({
title: root.querySelector('#title').innerText,
description: root.querySelector("#description").innerText,
id: 'asdf',
link: `${baseUrl}/${filename}`,
rawDate: root.querySelector("#date").innerText,
content: root.querySelector("article").innerHTML,
})
})
fs.mkdirSync('./public/rss', { recursive: true });
fs.writeFileSync('./public/rss/feed.xml', feed.rss2());
fs.writeFileSync('./public/rss/atom.xml', feed.atom1());
fs.writeFileSync('./public/rss/feed.json', feed.json1());