Skip to content

Commit 1761f17

Browse files
TechCielGGN-2015
andcommitted
library inventory page
Co-authored-by: GGN_2015 <[email protected]>
0 parents  commit 1761f17

File tree

10 files changed

+1068
-0
lines changed

10 files changed

+1068
-0
lines changed

.github/workflows/update.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Build Release
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [ main ]
7+
schedule:
8+
- cron: '28 * * * *'
9+
10+
jobs:
11+
build:
12+
name: Update
13+
runs-on: ubuntu-latest
14+
steps:
15+
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
19+
- name: Fetch data
20+
run: |
21+
. update.sh
22+
23+
- name: Push to release
24+
run: |
25+
git branch -D release || true
26+
git checkout --orphan release
27+
echo library.jlulug.org > CNAME
28+
git add data.json CNAME
29+
git config --local user.name "github-actions[bot]"
30+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
31+
git commit -m "built on $(date)"
32+
git push -f -u origin release

LICENSE

Lines changed: 661 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# LUG @ JLU 互助书柜
2+
3+
吉林大学 Linux 用户协会互助书柜的前端页面。
4+
5+
- `index.html` 前端渲染的独立页面
6+
- `style.css` 手搓的简易样式表
7+
- `vue.global.prod.js` Vue.js 3
8+
- `script.js` Vue 渲染逻辑
9+
- `paul-*.jpg` 背景图片
10+
11+
- `csv2json.py` 将 Google 表格提供的 CSV 转换成 JSON
12+
- `update.sh` 用于获取表格信息的脚本
13+
14+
15+
## 版权协议
16+
17+
本作品在 [GNU Affero 通用公共许可证第三版 (AGPLv3)](./LICENSE) 条件下开源。
18+
19+
部分文件来自外部,适用不同的版权协议:
20+
21+
- `vue.global.prod.js` 版权所有 2013 尤雨溪 (Evan You)
22+
-[MIT 许可证](https://opensource.org/licenses/MIT) 授权
23+
- `paul-melki-bByhWydZLW0-unsplash.jpg` 版权所有 2020 Paul Melki
24+
-[Unsplash 许可证](https://unsplash.com/license) 授权

csv2json.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import csv
2+
import json
3+
import sys
4+
5+
COLNAME_MAP = {
6+
"ISBN": ("isbn", str),
7+
"豆瓣ID": (b'', lambda _: _),
8+
"豆瓣*": ("url", str),
9+
"书名": ("name", str),
10+
"作者": ("author", str),
11+
"分类": ("tags", str),
12+
"可用数*": ("avail", int),
13+
"馆藏数*": ("total", int),
14+
"来源*": ("source", str),
15+
}
16+
17+
18+
def main() -> list:
19+
header, *body = list(csv.reader(sys.stdin))
20+
json.dump([
21+
{
22+
col[0]: col[1](line[i])
23+
for i, k in enumerate(header)
24+
if (col := COLNAME_MAP.get(k, (k, lambda x: x)))
25+
}
26+
for line in body
27+
], sys.stdout, ensure_ascii=False, skipkeys=True)
28+
29+
30+
if __name__ == "__main__":
31+
main()

index.html

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<!DOCTYPE html>
2+
<html lang="zh">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>LUG@JLU 互助书柜</title>
7+
<link rel="stylesheet" href="./style.css">
8+
</head>
9+
<body>
10+
<header>
11+
<h1>LUG @ JLU <br>互助书柜</h1>
12+
<p>
13+
<button onclick="window.open('https://jlulug.org/library/', '_blank')">借阅须知</button>
14+
</p>
15+
</header>
16+
17+
<main><div>
18+
<div v-if="!books.length" id="loading"></div>
19+
<table v-else v-cloak>
20+
<thead>
21+
<tr>
22+
<th>书名</th>
23+
<th>作者</th>
24+
<th>ISBN</th>
25+
<th>状态</th>
26+
<th>来源</th>
27+
<th>分类</th>
28+
</tr>
29+
</thead>
30+
<tbody>
31+
<tr v-for="book in books">
32+
<td><a :href="book.url">{{ book.name }}</a></td>
33+
<td>{{ book.author }}</td>
34+
<td>{{ book.isbn }}</td>
35+
<td v-if="book.avail">
36+
<mark class="available">可用 <span v-if="book.avail > 1">{{ book.avail }} 本</mark>
37+
</td>
38+
<td v-else>
39+
<mark class="unavailable">已借出</mark>
40+
</td>
41+
<td>{{ book.source }}</td>
42+
<td><div>
43+
<mark v-for="tag in book_tags(book.tags)" :style="{ backgroundColor: tag[1] }">
44+
{{ tag[0] }}
45+
</mark>
46+
</div></td>
47+
</tr>
48+
</tbody>
49+
</table>
50+
<footer>
51+
<p>本页面由<a href="https://jlulug.org" target="_blank">吉林大学 Linux 用户协会</a>维护,保留一切权利。</p>
52+
<p>吉林大学 Linux 用户协会是由 GNU/Linux 用户与爱好者自愿结成的注册社团,旨在联络沟通同道中人,推广 GNU/Linux 的使用,宣传自由软件的价值,培养开放社区氛围。</p>
53+
</footer>
54+
</div></main>
55+
56+
<script src="./vue.global.prod.js"></script>
57+
<script src="./script.js"></script>
58+
</body>
59+
</html>
51.3 KB
Loading

script.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const hash = s => Math.abs(s.split('').reduce((a,b) => (((a << 5) - a) + b.charCodeAt(0))|0, 0))
2+
const colors = ['#DB2828','#F2711C','#FBBD08','#B5CC18','#21BA45','#00B5AD','#2185D0',
3+
'#6435C9','#A333C8','#E03997','#A5673F','#767676','#1B1C1D']
4+
5+
const app = Vue.createApp({
6+
data() {
7+
return {
8+
books_raw: [],
9+
}
10+
},
11+
computed: {
12+
books() {
13+
// filter out books with no stock (historical)
14+
// sort available books before lent out books
15+
return [...this.books_raw].filter(x => x.total > 0).sort((a,b) => (!!b.avail)-(!!a.avail))
16+
},
17+
},
18+
methods: {
19+
book_tags(tag_str) {
20+
return tag_str.split(';') // split tag string by ;
21+
.map(x=>x.trim()) // remove whitespaces
22+
.filter(x=>x) // remove empty item (consecutive ;;)
23+
.map(x=>[x, colors[hash(x) % colors.length]]) // choose color by string hash
24+
},
25+
},
26+
async mounted() {
27+
this.books_raw = await (await fetch('./data.json')).json()
28+
},
29+
})
30+
31+
app.mount('main')

0 commit comments

Comments
 (0)