Skip to content

Commit

Permalink
feat: init index.js and vue
Browse files Browse the repository at this point in the history
  • Loading branch information
OrangeX4 committed Feb 14, 2022
0 parents commit 539ef18
Show file tree
Hide file tree
Showing 17 changed files with 1,769 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
.DS_Store
dist
dist-ssr
coverage
*.local

/cypress/videos/
/cypress/screenshots/

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["johnsoncodehk.volar", "johnsoncodehk.vscode-typescript-vue-plugin"]
}
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## FAQ

> 萌新也可以加 blog 列表么?
能。

> 有些blog太久没更新或失效了,怎么办?
请提pull request删掉

## 添加方式

**最下面一行**添加(相当于按时间顺序,为以后的增量提醒做准备)。

TUNA的同学们有权限可以直接编辑此文件;其它同学们烦请发 pull request。

推荐在 commit log 或者 pull request 里面简单介绍一下自己,比如常用的 ID 等。

## Lists

| Name | RSS | HTML |
| -- | -- | -- |
| OrangeX4's Blog | https://orangex4.cool/atom.xml | https://orangex4.cool/ |
| Cmj's Blog | https://blog.caomingjun.com/atom.xml | https://blog.caomingjun.com/ |
| Mexii's Blog | https://blog.mexii.one/atom.xml | https://blog.mexii.one/ |

## OPML

<https://tuna.github.io/blogroll/opml.xml>

在 Inoreader 里可以持续订阅,在 Feedly 里可以下载之后导入。

## See Also

- https://github.com/timqian/chinese-independent-blogs
66 changes: 66 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 文件读取包
const fs = require('fs')
// 引入 RSS 解析第三方包
const Parser = require('rss-parser');
const parser = new Parser();

// 相关配置
const opmlXmlContentTitle = 'NJU-LUG Blogroll';
const readmeMdPath = './README.md';
const opmlJsonPath = './web/src/assets/opml.json';
const dataJsonPath = './web/src/assets/data.json';
const maxDataJsonItemsNumber = 100;
const opmlXmlPath = './web/public/opml.xml';
const opmlXmlContentOp = '<opml version="2.0">\n <head>\n <title>' + opmlXmlContentTitle + '</title>\n </head>\n <body>\n\n';
const opmlXmlContentEd = '\n </body>\n</opml>';

// 解析 README 中的表格,转为 JSON
const pattern = /\| *([^\|]*) *\| *(http[^\|]*) *\| *(http[^\|]*) *\|/g;
const readmeMdContent = fs.readFileSync(readmeMdPath, { encoding: 'utf-8' });
// 生成 opml.json
const opmlJson = [];
let resultArray;
while ((resultArray = pattern.exec(readmeMdContent)) !== null) {
opmlJson.push({
title: resultArray[1].trim(),
xmlUrl: resultArray[2].trim(),
htmlUrl: resultArray[3].trim()
});
}
// 保存 opml.json 和 opml.xml
fs.writeFileSync(opmlJsonPath, JSON.stringify(opmlJson, null, 2), { encoding: 'utf-8' });
const opmlXmlContent = opmlXmlContentOp
+ opmlJson.map((lineJson) => ` <outline title="${lineJson.title}" xmlUrl="${lineJson.xmlUrl}" htmlUrl="${lineJson.htmlUrl}" />\n`).join('')
+ opmlXmlContentEd;
fs.writeFileSync(opmlXmlPath, opmlXmlContent, { encoding: 'utf-8' });

// 异步处理
(async () => {

// 用于存储各项数据
const dataJson = [];

for (const lineJson of opmlJson) {
const feed = await parser.parseURL(lineJson.xmlUrl);

// 数组合并
dataJson.push.apply(dataJson, feed.items.filter((item) => item.title && item.content && item.pubDate).map((item) => {
const pubDate = new Date(item.pubDate);
return {
name: lineJson.title,
xmlUrl: lineJson.xmlUrl,
htmlUrl: lineJson.htmlUrl,
title: item.title,
content: item.content,
pubDate: pubDate,
pubDateStr: pubDate.toISOString().split('T')[0]
}
}));
}

// 按时间顺序排序
dataJson.sort((itemA, itemB) => itemA.pubDate < itemB.pubDate ? 1 : -1);
// 默认为保存前 100 项的数据
fs.writeFileSync(dataJsonPath, JSON.stringify(dataJson.slice(0, Math.min(maxDataJsonItemsNumber, dataJson.length)), null, 2), { encoding: 'utf-8' });

})();
Loading

0 comments on commit 539ef18

Please sign in to comment.