228 lines
7.4 KiB
HTML
228 lines
7.4 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>RSS Reader</title>
|
||
<meta name="description" content='RSS Reader,一个将订阅信息聚合展示的开源web工具,便于了解近期关注的信息,同时页面数据数据也实现了自动刷新。'>
|
||
<meta name="keywords" content="<< .Keywords >>">
|
||
<meta name="anthor" content="srcrs">
|
||
<!-- <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"> -->
|
||
<link rel="stylesheet" href="static/index.min.css">
|
||
<< if .DarkMode >>
|
||
<link rel="stylesheet" href="static/dark-mode.css">
|
||
<< end >>
|
||
<link rel="icon" href="static/favicon.svg" type="image/x-icon">
|
||
<style>
|
||
body {
|
||
font-family: "Avenir", Helvetica, Arial, sans-serif;
|
||
-webkit-font-smoothing: antialiased;
|
||
-moz-osx-font-smoothing: grayscale;
|
||
text-align: center;
|
||
color: #2c3e50;
|
||
margin-top: 30px;
|
||
}
|
||
|
||
.card-header {
|
||
display: flex;
|
||
justify-content: center;
|
||
align-items: center;
|
||
font-size: 18px;
|
||
font-weight: bold;
|
||
}
|
||
|
||
.list-item {
|
||
display: flex;
|
||
align-items: center;
|
||
text-align: left;
|
||
width: 100%;
|
||
}
|
||
|
||
.list-item-title {
|
||
display: flex;
|
||
/* white-space: nowrap;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis; */
|
||
flex-grow: 1;
|
||
text-align: left;
|
||
width: 100%;
|
||
margin-bottom: 10px;
|
||
}
|
||
|
||
a {
|
||
color: black;
|
||
text-decoration: none;
|
||
}
|
||
|
||
a:hover {
|
||
text-decoration: underline;
|
||
}
|
||
.feed-col {
|
||
margin-bottom: 20px;
|
||
}
|
||
|
||
.time {
|
||
font-size: 12px;
|
||
color: #999;
|
||
}
|
||
</style>
|
||
</head>
|
||
|
||
<body>
|
||
<div id="app">
|
||
<el-container>
|
||
<el-header>
|
||
<h1>
|
||
RSS Reader
|
||
<< if gt .AutoUpdatePush 0 >>
|
||
<br/>
|
||
<span>{{ countdown }} s</span>
|
||
<< end >>
|
||
</h1>
|
||
</el-header>
|
||
<el-main v-loading.fullscreen.lock="fullscreenLoading" element-loading-text="拼命加载中">
|
||
<el-row :gutter="20">
|
||
<< range $index, $feed :=.RssDataList >>
|
||
<el-col v-if="showSEOFlag" :xs="24" :sm="12" :md="8" :lg="6" :key="index" class="feed-col">
|
||
<el-card class="box-card">
|
||
<div slot="header" class="card-header">
|
||
<span>
|
||
<< $feed.Title >>
|
||
</span>
|
||
</div>
|
||
<el-scrollbar style="height: 300px;">
|
||
<< range $i, $item :=$feed.Items >>
|
||
<el-list key="<< $i >>">
|
||
<el-list-item>
|
||
<div class="list-item-title">
|
||
<span>
|
||
<< inc $i >>.
|
||
</span>
|
||
<el-link href="<< $item.Link >>" target="_blank" title="<< $item.Title >>">
|
||
<< $item.Title >>
|
||
</el-link>
|
||
</div>
|
||
</el-list-item>
|
||
</el-list>
|
||
<< end >>
|
||
</el-scrollbar>
|
||
<div slot="footer" class="card-footer" style="height: 10px;">
|
||
<time class="time">
|
||
<< $feed.Custom.lastupdate >>
|
||
</time>
|
||
</div>
|
||
</el-card>
|
||
</el-col>
|
||
<< end>>
|
||
<el-col :xs="24" :sm="12" :md="8" :lg="6" v-for="(feed, index) in feeds" :key="index" class="feed-col">
|
||
<el-card class="box-card">
|
||
<div slot="header" class="card-header">
|
||
<span>{{ feed.title }}</span>
|
||
</div>
|
||
<el-scrollbar style="height: 300px;">
|
||
<el-list v-for="(item, i) in feed.items" :key="i">
|
||
<el-list-item>
|
||
<div class="list-item-title">
|
||
<span>{{ i+1 }}. </span>
|
||
<el-link :href="item.link" target="_blank" :title="item.title">{{ item.title }}</el-link>
|
||
</div>
|
||
</el-list-item>
|
||
</el-list>
|
||
</el-scrollbar>
|
||
<div slot="footer" class="card-footer" style="height: 10px;">
|
||
<time class="time">{{ feed.custom.lastupdate }}</time>
|
||
</div>
|
||
</el-card>
|
||
</el-col>
|
||
</el-row>
|
||
</el-main>
|
||
<el-footer>
|
||
<el-link href="https://github.com/srcrs/rss-reader" target="_blank">Rss-reader</el-link>
|
||
<span> | </span>
|
||
<el-link href="https://github.com/srcrs" target="_blank">By srcrs</el-link>
|
||
</el-footer>
|
||
</el-container>
|
||
</div>
|
||
|
||
<!-- <script src="https://unpkg.com/vue@next"></script> -->
|
||
<script src="static/vue.global.prod.js"></script>
|
||
|
||
<!-- <script src="https://cdn.bootcdn.net/ajax/libs/element-plus/2.3.3/index.full.js"></script> -->
|
||
<script src="static/index.full.min.js"></script>
|
||
<script>
|
||
const app = Vue.createApp({
|
||
data() {
|
||
return {
|
||
feeds: [],
|
||
showSEOFlag: true,
|
||
fullscreenLoading: true,
|
||
countdown: 60,
|
||
autoUpdatePush: << .AutoUpdatePush >>,
|
||
};
|
||
},
|
||
async created() {
|
||
this.fullscreenLoading = false;
|
||
},
|
||
async mounted() {
|
||
const protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://';
|
||
const connect = () => {
|
||
const socket = new WebSocket(protocol + window.location.host + "/ws");
|
||
// 使用媒体查询判断设备类型
|
||
const isMobile = window.matchMedia('(max-width: 767px)').matches;
|
||
socket.onmessage = event => {
|
||
const feed = JSON.parse(event.data);
|
||
const existingFeed = this.feeds.find(f => f.link === feed.link);
|
||
if (existingFeed) {
|
||
Object.assign(existingFeed, feed);
|
||
} else {
|
||
this.feeds.push(feed);
|
||
}
|
||
this.showSEOFlag = false;
|
||
};
|
||
const reloadHtml = () => {
|
||
if (socket.readyState === WebSocket.CLOSED || socket.readyState === WebSocket.CLOSING) {
|
||
if (document.visibilityState === 'visible') {
|
||
// 刷新网页
|
||
console.log("reload...")
|
||
location.reload();
|
||
}
|
||
}
|
||
}
|
||
socket.onclose = event => {
|
||
if (!isMobile && this.autoUpdatePush > 0) {
|
||
console.log("WebSocket closed. Reconnecting...");
|
||
setInterval(reloadHtml, 3000);
|
||
}
|
||
};
|
||
// Send heartbeat message every 60 seconds
|
||
const sendHeartbeat = () => {
|
||
if (socket.readyState === WebSocket.OPEN) {
|
||
socket.send("heartbeat");
|
||
} else if (socket.readyState === WebSocket.CLOSED || socket.readyState === WebSocket.CLOSING) {
|
||
reloadHtml()
|
||
}
|
||
};
|
||
if (!isMobile && this.autoUpdatePush > 0) {
|
||
setInterval(sendHeartbeat, 60000);
|
||
setInterval(() => {
|
||
if (this.countdown > 0) {
|
||
this.countdown--;
|
||
} else {
|
||
this.countdown = 60;
|
||
}
|
||
}, 1000);
|
||
}
|
||
};
|
||
connect();
|
||
},
|
||
beforeDestroy() {
|
||
// 在组件销毁前手动关闭 WebSocket 连接
|
||
this.socket.close();
|
||
}
|
||
});
|
||
|
||
app.use(ElementPlus);
|
||
app.mount("#app");
|
||
</script>
|
||
</body>
|
||
</html> |