Skip to content

Commit

Permalink
refactor(mastodon): rm mastodon api and renderer locally
Browse files Browse the repository at this point in the history
  • Loading branch information
eallion committed Nov 18, 2023
1 parent be1788b commit 6b40918
Show file tree
Hide file tree
Showing 12 changed files with 1,282 additions and 174 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/douban.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# .github/workflows/douban.yml
name: Sync Douban Data

on:
schedule:
- cron: "0 */12 * * *"
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/download-mastodon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Fetch mastodon status

on:
# schedule:
# - cron: "0 17 * * *"
# watch:
# types: [started]

workflow_dispatch:
repository_dispatch:
types:
# mastodon webhook
- mastodon-update

jobs:
mastodon:
name: Fetch mastodon status
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

# 下载最新的 Mastodon
- name: Download Mastodon Status
run: |
cd data/mastodon/
rm data/mastodon/mastodon.json
url="https://e5n.cc/api/v1/accounts/111136231674527355/statuses?limit=10&exclude_replies=true&exclude_reblogs=true"
output="mastodon.json"
curl -s "$url" >"$output"
# 把修改后的数据提交到 GitHub 仓库
- name: Git Add and Commit
if: ${{ env.REMOTE_COUNT != env.CURRENT_COUNT }}
uses: EndBug/add-and-commit@v9
with:
message: 'chore(data): fetch mastodon status'
add: |
'./data/mastodon'
# 调用另外的 GitHub Actions 构建 Hugo
- name: Build Hugo and Deploy
uses: peter-evans/repository-dispatch@v2
with:
event-type: "Build Hugo and Deploy"
2 changes: 1 addition & 1 deletion .github/workflows/neodb.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# .github/workflows/douban.yml
name: Sync NeoDB Data

on:
schedule:
- cron: "0 17 * * *"
Expand Down
56 changes: 31 additions & 25 deletions assets/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
// }

// 首页嘀咕
// 首页嘀咕已经静态化
// 远程 JSON API 地址
let jsonUrl = "https://api.eallion.com/mastodon/api/v1/accounts/111136231674527355/statuses?limit=10&exclude_replies=true&exclude_reblogs=true";
// let jsonUrl = "https://api.eallion.com/mastodon/api/v1/accounts/111136231674527355/statuses?limit=10&exclude_replies=true&exclude_reblogs=true";

// 相对时间插件 2.5.2 https://tokinx.github.io/lately/
(() => {
Expand Down Expand Up @@ -69,29 +70,34 @@ let jsonUrl = "https://api.eallion.com/mastodon/api/v1/accounts/1111362316745273

// 处理 Json 数据
if (document.querySelector('#ticker')) {
fetch(jsonUrl)
.then(res => res.json())
.then(res => {
var result = '';
var data = res;
for (var i = 0; i < data.length; i++) {
var tickerTime = new Date(data[i].created_at).toLocaleString();
var tickerContent = pangu.spacing(getSimpleText(data[i].content))
result += `<li class="item"><span class="item-detail">嘀咕:<a href="/toot/">${tickerContent}</a></span><span>&lsqb;<span class="datetime">${tickerTime}</span>&rsqb;</span></li>`;
console.log(tickerContent)
}
var tickerDom = document.querySelector('#ticker');
var tickerBefore = `<i class="fab fa-mastodon"></i><div class="ticker-wrap"><ul class="ticker-list">`;
var tickerAfter = `</ul></div>`;
resultAll = tickerBefore + result + tickerAfter;
tickerDom.innerHTML = resultAll;
// 首页嘀咕已经静态化
// fetch(jsonUrl)
// .then(res => res.json())
// .then(res => {
// let result = '';
// let resultAll = '';
// var data = res;
// for (var i = 0; i < data.length; i++) {
// var tickerTime = new Date(data[i].created_at).toLocaleString();
// var tickerContent = pangu.spacing(getSimpleText(data[i].content))
// result += `<li class="item"><span class="item-detail"><i class="fab fa-mastodon"></i>嘀咕:<a href="/toot/">${tickerContent}</a></span><span>&lsqb;<span class="datetime">${tickerTime}</span>&rsqb;</span></li>`;
// console.log(tickerContent)
// }
// var tickerDom = document.querySelector('#ticker');
// var tickerBefore = `<div class="ticker-wrap"><ul class="ticker-list">`;
// var tickerAfter = `</ul></div>`;
// resultAll = tickerBefore + result + tickerAfter;
// tickerDom.innerHTML = resultAll;

// // 相对时间插件
// window.Lately && Lately.init({
// target: '.datetime'
// });
// });
// 相对时间插件
window.Lately && Lately.init({
target: '.datetime'
});
});

// 滚动效果
setInterval(function () {
var tickerWrap = document.querySelector(".ticker-list");
Expand All @@ -104,12 +110,12 @@ if (document.querySelector('#ticker')) {
}, 2000);
}

// 提取 HTML 代码中的纯文本内容
function getSimpleText(html) {
var htmlTags = new RegExp("<.+?>", "g");
var simpleText = html.replace(htmlTags, '');
return simpleText;
}
// // 提取 HTML 代码中的纯文本内容
// function getSimpleText(html) {
// var htmlTags = new RegExp("<.+?>", "g");
// var simpleText = html.replace(htmlTags, '');
// return simpleText;
// }

// 首页嘀咕结束

Expand Down
2 changes: 1 addition & 1 deletion assets/js/custom.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6b40918

Please sign in to comment.