diff --git a/package-lock.json b/package-lock.json index c180f35..3b08453 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "fs": "^0.0.1-security", "hbs": "^4.2.0", "japanese-date-converter": "^2.0.0", + "rss": "^1.2.2", "serve-index": "^1.9.1" }, "devDependencies": { @@ -1001,6 +1002,37 @@ "node": ">= 0.8" } }, + "node_modules/rss": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/rss/-/rss-1.2.2.tgz", + "integrity": "sha512-xUhRTgslHeCBeHAqaWSbOYTydN2f0tAzNXvzh3stjz7QDhQMzdgHf3pfgNIngeytQflrFPfy6axHilTETr6gDg==", + "license": "MIT", + "dependencies": { + "mime-types": "2.1.13", + "xml": "1.0.1" + } + }, + "node_modules/rss/node_modules/mime-db": { + "version": "1.25.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.25.0.tgz", + "integrity": "sha512-5k547tI4Cy+Lddr/hdjNbBEWBwSl8EBc5aSdKvedav8DReADgWJzcYiktaRIw3GtGC1jjwldXtTzvqJZmtvC7w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/rss/node_modules/mime-types": { + "version": "2.1.13", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.13.tgz", + "integrity": "sha512-ryBDp1Z/6X90UvjUK3RksH0IBPM137T7cmg4OgD5wQBojlAiUwuok0QeELkim/72EtcYuNlmbkrcGuxj3Kl0YQ==", + "license": "MIT", + "dependencies": { + "mime-db": "~1.25.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -1527,6 +1559,12 @@ "engines": { "node": ">=8" } + }, + "node_modules/xml": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz", + "integrity": "sha512-huCv9IH9Tcf95zuYCsQraZtWnJvBtLVE0QHMOs8bWyZAFZNDcYjsPq1nEx8jKA9y+Beo9v+7OBPRisQTjinQMw==", + "license": "MIT" } } } diff --git a/package.json b/package.json index 9a464e3..7a37fd5 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "fs": "^0.0.1-security", "hbs": "^4.2.0", "japanese-date-converter": "^2.0.0", + "rss": "^1.2.2", "serve-index": "^1.9.1" }, "devDependencies": { diff --git a/src/router/common_path_logic/home.js b/src/router/common_path_logic/home.js index 2f5a73b..0978673 100644 --- a/src/router/common_path_logic/home.js +++ b/src/router/common_path_logic/home.js @@ -4,7 +4,9 @@ const rootDir = dirname(require.main.filename); module.exports = async (req, res) => { try{ - const commentsRead = (await readCsv(rootDir + '/public/dynamic/sync/comments.csv')) + const commentsRead = (await readCsv(rootDir + '/public/dynamic/sync/comments.csv')).filter(c => { + return c.approved === "1" + }) const comments = commentsRead.slice(commentsRead.length-16, commentsRead.length).reverse() return { comments diff --git a/src/router/common_path_logic/update_log.js b/src/router/common_path_logic/update_log.js new file mode 100644 index 0000000..946d188 --- /dev/null +++ b/src/router/common_path_logic/update_log.js @@ -0,0 +1,36 @@ +const { dirname } = require("path"); +const { readCsv } = require("../../utils/csv") +const thisDirectory = dirname(require.main.filename); + +async function getUpdates(){ + const csvData = await readCsv(thisDirectory + '/public/dynamic/sync/updates.csv') + + const updates = [] + let currentYear = "" + for (let i = csvData.length-1; i > -1; i--){ + const {date, description, link} = csvData[i] + const codeDate = new Date(date) + const updateYear = codeDate.getFullYear() + const updateDayMonth = codeDate.getDay() + '/' + (codeDate.getMonth()+1) + + if (updateYear !== currentYear){ + currentYear = updateYear + updates.push({ + year: currentYear, + updates: [] + }) + } + updates[updates.length-1].updates.push({ + date, + description, + link, + updateDayMonth + }) + } + + return { + updates + } +} + +module.exports = getUpdates \ No newline at end of file diff --git a/src/router/indexRouter.js b/src/router/indexRouter.js index ea6d0f5..682e3e8 100644 --- a/src/router/indexRouter.js +++ b/src/router/indexRouter.js @@ -4,7 +4,8 @@ const router = express.Router(); const { readCsv } = require('../utils/csv'); const { dirname } = require('path'); const thisDirectory = dirname(require.main.filename); -const fs = require('fs') +const fs = require('fs'); +const makeRss = require('../utils/rss'); function addPaths(path, renderParams = {}){ let currentDefaultParams = {...renderParams} @@ -69,11 +70,26 @@ router.post('/comment', (req, res) => { timeout: 3600 }) const comment = req.body.comment.replace(/"/g, '""'); - fs.appendFileSync(thisDirectory + "/public/dynamic/sync/comments.csv", `\n${Date.now()},"${comment}",,1`) + fs.appendFileSync(thisDirectory + "/public/dynamic/sync/comments.csv", `\n${Date.now()},"${comment}",,0`) res.redirect('/home#visitor_table') }) +router.get('/update_log/rss', async (_req, res) => { + const csvData = await readCsv(thisDirectory + '/public/dynamic/sync/updates.csv') + const rss = makeRss('https://lyricaltokarev.com/update_log/rss', "Update Log") + csvData.forEach((u, i) => { + rss.item({ + title: "Update #" + i, + description: `${u.link && ``}${u.description}${u.link && ``}`, + author: "Gor Down", + date: u.date + }) + }) + const xml = rss.xml({indent: true}) + res.setHeader('Content-Type', 'text/xml'); + res.send(xml) +}) setInterval(() => { recent_posters.forEach(poster => { diff --git a/src/utils/rss.js b/src/utils/rss.js new file mode 100644 index 0000000..f39e2b3 --- /dev/null +++ b/src/utils/rss.js @@ -0,0 +1,13 @@ +const RSS = require("rss") + +function makeRss(feed_link, name, description, link){ + return new RSS({ + title: `Lyrical Tokarev${name ? ` ~ ${name}` : ""}`, + site_url: link ? link : "https://lyricaltokarev.com/home", + feed_url: feed_link, + description: description ? description : "Anime site.", + managingEditor: "gor@lyricaltokarev.com (Gor Down)" + }) +} + +module.exports = makeRss \ No newline at end of file diff --git a/views/home.hbs b/views/home.hbs index 0875d2c..3560eab 100644 --- a/views/home.hbs +++ b/views/home.hbs @@ -24,7 +24,8 @@
  • Creator
  • Opinion
  • Art
  • -
  • Motivation
  • +
  • Technologies
  • +
  • Motivation
  • ç
  • Community
  • Toxic
  • Views
  • @@ -34,6 +35,7 @@
  • Develop
  • Saturated
  • Right
  • +
  • Left
  • Life
  • Tweet
  • Obscure
  • @@ -50,6 +52,7 @@
  • Yikes
  • Project
  • Idea
  • +
  • Pibes/Pibas
  • Identity
  • Global
  • Emotional
  • @@ -187,6 +190,9 @@ + + +