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 1c7571c
Show file tree
Hide file tree
Showing 17 changed files with 403 additions and 177 deletions.
9 changes: 8 additions & 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 All @@ -8,6 +8,7 @@ on:

workflow_dispatch:
repository_dispatch:
types: [sync-douban]

jobs:
douban:
Expand Down Expand Up @@ -72,3 +73,9 @@ jobs:
with:
message: 'chore(data): update douban data'
add: './data/douban'

# 调用另外的 GitHub Actions
- name: Sync NeoDB Data
uses: peter-evans/repository-dispatch@v2
with:
event-type: sync-neodb
42 changes: 42 additions & 0 deletions .github/workflows/download-mastodon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Fetch mastodon status

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

workflow_dispatch:
repository_dispatch:
types: [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 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
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
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
# - cron: 0 16 * * *
workflow_dispatch:
repository_dispatch:
types: [build-hugo]

jobs:
build-deploy:
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/neodb.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# .github/workflows/douban.yml
name: Sync NeoDB Data

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

workflow_dispatch:
repository_dispatch:
types: [sync-neodb]

jobs:
douban:
Expand Down Expand Up @@ -157,7 +159,7 @@ jobs:
if: ${{ env.REMOTE_COUNT != env.CURRENT_COUNT }}
uses: peter-evans/repository-dispatch@v2
with:
event-type: "Build Hugo and Deploy"
event-type: build-hugo

# # 把海报上传到腾讯云
# - name: Upload Cover to Tencent COS
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.

1 change: 1 addition & 0 deletions content/links.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ aliases:
{{< friend name="东评西就" bio="小饿,专注科技互联网、社交媒体运营" url="https://dongjunke.cn" domain="dongjunke.cn" avatar="https://pic.yunshusong.cn/upic/20230204122856.jpg" >}}
{{< friend name="Yuxi & Yuqi" bio="Design loser,slack off champion." url="https://yuxiyuqi.com/" domain="yuxiyuqi.com" avatar="https://img.yuxiyuqi.com/2023/07/202307292154832.png" >}}
{{< friend name="文武科技柜" bio="文武科技社的后花园" url="https://www.wangdu.site/" domain="wangdu.site" avatar="https://www.wangdu.site/wp-content/uploads/2021/08/favicon.png" >}}
{{< friend name="lehhair's Blog" bio="人似秋鸿来有信,事如春梦了无痕" url="https://blog.lehhair.net/" domain="blog.lehhair.net" avatar="https://blog.lehhair.net/upload/logo.jpg" >}}
</div>

---
Expand Down
1 change: 1 addition & 0 deletions content/links.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ aliases:
{{< friend name="东评西就" bio="小饿,专注科技互联网、社交媒体运营" url="https://dongjunke.cn" domain="dongjunke.cn" avatar="https://pic.yunshusong.cn/upic/20230204122856.jpg" >}}
{{< friend name="Yuxi & Yuqi" bio="Design loser,slack off champion." url="https://yuxiyuqi.com/" domain="yuxiyuqi.com" avatar="https://img.yuxiyuqi.com/2023/07/202307292154832.png" >}}
{{< friend name="文武科技柜" bio="文武科技社的后花园" url="https://www.wangdu.site/" domain="wangdu.site" avatar="https://www.wangdu.site/wp-content/uploads/2021/08/favicon.png" >}}
{{< friend name="lehhair's Blog" bio="人似秋鸿来有信,事如春梦了无痕" url="https://blog.lehhair.net/" domain="blog.lehhair.net" avatar="https://blog.lehhair.net/upload/logo.jpg" >}}
</div>

---
Expand Down
1 change: 1 addition & 0 deletions data/mastodon/mastodon.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions example/links.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ aliases:
{{< friend name="东评西就" bio="小饿,专注科技互联网、社交媒体运营" url="https://dongjunke.cn" domain="dongjunke.cn" avatar="https://pic.yunshusong.cn/upic/20230204122856.jpg" >}}
{{< friend name="Yuxi & Yuqi" bio="Design loser,slack off champion." url="https://yuxiyuqi.com/" domain="yuxiyuqi.com" avatar="https://img.yuxiyuqi.com/2023/07/202307292154832.png" >}}
{{< friend name="文武科技柜" bio="文武科技社的后花园" url="https://www.wangdu.site/" domain="wangdu.site" avatar="https://www.wangdu.site/wp-content/uploads/2021/08/favicon.png" >}}
{{< friend name="lehhair's Blog" bio="人似秋鸿来有信,事如春梦了无痕" url="https://blog.lehhair.net/" domain="blog.lehhair.net" avatar="https://blog.lehhair.net/upload/logo.jpg" >}}
</div>

---
Expand Down
1 change: 1 addition & 0 deletions example/links.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ aliases:
{{< friend name="东评西就" bio="小饿,专注科技互联网、社交媒体运营" url="https://dongjunke.cn" domain="dongjunke.cn" avatar="https://pic.yunshusong.cn/upic/20230204122856.jpg" >}}
{{< friend name="Yuxi & Yuqi" bio="Design loser,slack off champion." url="https://yuxiyuqi.com/" domain="yuxiyuqi.com" avatar="https://img.yuxiyuqi.com/2023/07/202307292154832.png" >}}
{{< friend name="文武科技柜" bio="文武科技社的后花园" url="https://www.wangdu.site/" domain="wangdu.site" avatar="https://www.wangdu.site/wp-content/uploads/2021/08/favicon.png" >}}
{{< friend name="lehhair's Blog" bio="人似秋鸿来有信,事如春梦了无痕" url="https://blog.lehhair.net/" domain="blog.lehhair.net" avatar="https://blog.lehhair.net/upload/logo.jpg" >}}
</div>

---
Expand Down
74 changes: 74 additions & 0 deletions layouts/_default/toot copy.html.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{{- define "title" }}{{ .Title }} - {{ .Site.Title }}{{ end -}}

{{- define "content" -}}
{{- $params := .Scratch.Get "params" -}}
{{- $toc := $params.toc -}}
{{- if eq $toc true -}}
{{- $toc = .Site.Params.page.toc | default dict -}}
{{- else if eq $toc false -}}
{{- $toc = dict "enable" false -}}
{{- end -}}

<link rel="stylesheet" href="/assets/toot/mastodon-timeline.min.css?v=3.9.1-3.10.4">
<link rel="stylesheet" href="/assets/toot/mastodon-timeline-custom.min.css?v=2023.10.16">

<article class="page single special">
<h1 class="single-title animate__animated animate__pulse animate__faster">{{ .Title }}</h1>
<div id="content" class="content">
<div class="greyQuote">
<blockquote>
<div class="hitokoto">
<span id="hitokoto"></span> - <cite><span id="author"></span></cite>
</div>
</blockquote>
</div>
<div class="dummy-container">
<div class="mt-timeline">
<div id="mt-body" class="mt-body" role="feed">
<div class="loading-spinner"></div>
</div>
</div>
</div>
</div>
</article>

<script>
// Hitokoto API
if (window.location.href.includes("/en/")) {
fetch("https://api.github.com/zen")
.then(response => response.text())
.then(data => {
const zen = document.querySelector('#hitokoto');
zen.innerText = data;
const author = document.querySelector('#author');
author.innerText = "GitHub Zen";
})
.catch(console.error);
} else {
// fetch("https://api.eallion.com/hitokoto?c=k&charset=utf-8&encode=json")
fetch("https://api.eallion.com/poisonous.json")
.then(response => response.json())
.then(data => {
const hitokoto = document.querySelector('#hitokoto');
// hitokoto.innerText = data.hitokoto;
hitokoto.innerText = data.content;
const author = document.querySelector('#author');
author.innerText = '佚名';
})
.catch(console.error);
}
</script>

<script type="text/javascript" src="/assets/toot/moment.min.js?v=2.29.4"></script>

{{ if eq .Site.LanguageCode "en" }}
<script type="text/javascript" src="/assets/toot/moment.twitter.en.min.js"></script>
{{ else }}
<script type="text/javascript" src="/assets/toot/moment.twitter.min.js"></script>
{{ end }}

<script type="text/javascript" src="/assets/toot/mastodon-timeline.min.js?v=3.9.1-3.10.4"></script>

<!-- <script type="module" src="/assets/toot/reactions.min.js?v=1.0.11"></script> -->

{{- end -}}
Loading

0 comments on commit 1c7571c

Please sign in to comment.