chinese-independent-blogs/script.js

162 lines
6.0 KiB
JavaScript
Raw Permalink Normal View History

/**
* 1. Get original CSV of feeds
* 2. Get follower counts for each feed
* 3. Order by follower count
*/
2019-10-23 12:11:47 +08:00
const fs = require('fs');
2019-10-24 15:26:07 +08:00
const markdownTable = require('markdown-table');
2019-10-23 12:11:47 +08:00
const data = fs.readFileSync('./blogs-original.csv');
const rows = data.toString().split('\n');
const table = rows
2019-10-24 15:26:07 +08:00
.map(row => row.split(',').map(column => column.trim()))
2019-12-10 16:57:31 +08:00
.filter((row, i) => row.length === 4 && i !== 0)
.map(row => row.push(-1) && row) // row[4] to store count of RSS subscribers
const { GraphQLClient } = require('graphql-request');
const endpoint = 'https://api.feeds.pub/graphql'
const client = new GraphQLClient(endpoint, {errorPolicy: "ignore"});
2019-10-24 15:26:07 +08:00
2022-08-19 19:04:43 +08:00
const pageSize = 60;
2019-10-24 15:26:07 +08:00
async function getResultAndUpdateREADME() {
// Get follower counts
const feedLinks = table.map(row => row[2]);
const queries = feedLinks.map((feedLink, i) => {
if (feedLink) {
return `f${i}: feed(id: "${feedLink}") {
followerCount
}`
} else return '';
2022-08-19 18:40:00 +08:00
}).filter(query => query.trim().length > 0);
for (let i = 0; i < queries.length; i += pageSize) {
const query = `{
${queries.slice(i, i + pageSize).join('\n')}
}`
2022-08-19 19:04:43 +08:00
try {
const data = await client.request(query);
Object.keys(data).forEach(key => {
const index = Number(key.replace('f', ''));
const count = data[key] ? data[key].followerCount : 0;
table[index][4] = count;
});
console.log(`Got followerCount for ${i} to ${i + pageSize}`);
} catch (error) {
console.log(error)
}
2019-10-24 15:26:07 +08:00
}
// Order by follower count
table.sort((a, b) => (b[4] - a[4]) || (a[0] - b[0]));
2019-10-24 15:26:07 +08:00
const getFeedsPubBtn = (feedLink, followCount) =>
2022-08-19 19:10:17 +08:00
`[<img src="https://img.shields.io/static/v1?label=follow&message=${followCount}&style=social&logo=rss">](https://feeds.pub/feed/${encodeURIComponent(feedLink)})`;
2022-08-19 19:11:47 +08:00
const newTable = table.map(row => {
return [
row[2] ? getFeedsPubBtn(row[2], row[4]) : '',
row[0].replace(/\|/g, '&#124;'),
2023-09-15 10:33:14 +08:00
row[1],
row[3]
]
2019-11-01 17:23:40 +08:00
});
2019-10-24 15:26:07 +08:00
// update README
const tableContentInMD = markdownTable([['<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RSS 订阅数</p>', '简介', '链接', '标签'], ...newTable]);
2019-10-24 15:26:07 +08:00
2020-03-31 19:03:36 +08:00
const readmeContent = `
# 中文独立博客列表
2019-10-24 15:26:07 +08:00
2022-05-15 01:23:04 +08:00
[![](https://badgen.net/badge/icon/Website?icon=chrome&label)](https://feeds.pub/cn-indie) [![](https://badgen.net/badge/icon/Telegram?icon=telegram&label)](https://t.me/indieBlogs) [![](https://badgen.net/badge/icon/Blog?icon=chrome&label)](https://blog.t9t.io/cn-indie-blogs-2019-10-29/)
2019-10-24 15:26:07 +08:00
2021-09-22 15:40:57 +08:00
## Sponsors
2022-05-15 01:16:39 +08:00
[琚致远](https://github.com/juzhiyuan) | [Bytebase](https://bytebase.com/) | [Madao](https://madao.me/) | [SecondState](https://bit.ly/3gfWwps)
2021-09-22 15:40:57 +08:00
2022-05-15 01:15:15 +08:00
[Become a sponsor](https://github.com/sponsors/timqian)
2021-09-22 15:40:57 +08:00
2019-10-24 15:26:07 +08:00
## 目录
- [博客列表](#博客列表)
- [什么是独立博客](#什么是独立博客)
- [如何提交](#如何提交)
- [为什么要收集这张列表](#为什么要收集这张列表)
## 博客列表
> 暂时根据各 RSS 服务订阅数据排了个先后顺序 欢迎加入 [Telegram ](https://t.me/indieBlogs) 讨论如何更好地组织和利用这个列表
2019-10-24 15:26:07 +08:00
${tableContentInMD}
## 什么是独立博客
- 拥有自己的域名
- 作者本人原创内容
### 如何提交
2023-03-06 12:46:19 +08:00
1. [./blogs-original.csv](./blogs-original.csv) 尾部添加一行填入博客的 名称URLRSS以及标签
2019-10-24 15:26:07 +08:00
2. 提交 PR
2020-08-31 10:28:52 +08:00
3. (自动) PR merge 之后 README 通过 [./script.js](./script.js) 生成
2019-10-24 15:26:07 +08:00
## 为什么要收集这张列表
不止一次听到有人说在中国, 独立博客的时代已经过去了确实很多博主都转到了公众号知乎专栏小密圈微博
这些平台读者比较多他们的推荐算法可以让你的内容被更多人看到
但我还是更喜欢独立博客因为有属于自己的域名因为可以自由地排版自由地说话
2019-10-24 15:26:07 +08:00
不得不承认独立博客在如何获取新读者方面确实存在问题酒香也怕巷子深同样的内容放在自己的博客和上述的自媒体平台哪怕有自己的主动宣传读者的增长速度看起来也远不及自媒体平台上的增粉速度对吧
2019-10-24 15:26:07 +08:00
是否可以做一个工具可以连接这些独立博主在保持独立博客的自由的同时组织一个独立博客的创作和读者群体让独立博客们也有一个稳定的被发现的渠道这个工具可能是一个带个性化推荐系统的 RSS 客户端可能是一个类似微博twitter 但是主要内容是独立博客的新东西读者可以点赞评论可以知道我们 follow 的博主 follow 了谁
2019-10-24 15:26:07 +08:00
2023-01-29 15:20:16 +08:00
这个列表是一个开始先把独立博客们收集起来欢迎加入 [Telegram ](https://t.me/indieBlogs)一起思考和讨论如何构建这样一个工具。
2019-10-29 09:53:46 +08:00
## Thanks
- https://feedly.com
- t9t.io community: https://wewe.t9t.io/chat/t9t.io%20community%202 https://wewe.t9t.io/chat/t9t.io%20community
- https://github.com/DIYgod/RSSHub
- https://ohmyrss.com/
- https://github.com/tangqiaoboy/iOSBlogCN
2019-10-30 16:23:14 +08:00
- https://www.zhihu.com/question/19928148
2019-11-01 11:28:09 +08:00
## 博客构建工具推荐
2022-04-21 14:21:16 +08:00
- [Blogdown](https://github.com/rstudio/blogdown)
- [Docusaurus](https://docusaurus.io/)
- [Gatsby](https://gatsbyjs.org/)
- [Ghost](https://ghost.org/)
- [Gridea](https://gridea.dev/)
- [Halo](https://github.com/halo-dev/halo)
- [Hexo](https://hexo.io/)
- [Hugo](https://gohugo.io/)
- [Jekyll](https://jekyllrb.com/)
- [Pelican](https://blog.getpelican.com/)
- [Saber](https://saber.land/)
- [Typecho](https://typecho.org)
- [Vuepress](https://vuepress.vuejs.org/)
- [Wordpress](https://wordpress.com/)
- [Wowchemy](https://wowchemy.com)
2022-10-23 14:27:36 +08:00
- [Astro](https://astro.build)
- [Vanblog](https://vanblog.mereith.com/)
2022-04-21 14:21:16 +08:00
## 博客部署工具推荐
- [Netlify](https://www.netlify.com/)
- [Vercel](https://vercel.com/)
- [Cloudflare Pages](https://pages.cloudflare.com/)
2019-11-01 11:28:09 +08:00
`
2019-10-24 15:26:07 +08:00
fs.writeFileSync('./README.md', readmeContent, 'utf8');
console.log('README.md 文件生成成功!');
2019-10-24 15:26:07 +08:00
}
2019-10-23 12:11:47 +08:00
2019-10-24 15:26:07 +08:00
getResultAndUpdateREADME()