diff --git a/data/config.json b/data/config.json index 19459f8..81aec5c 100644 --- a/data/config.json +++ b/data/config.json @@ -14,5 +14,8 @@ "url": "https://github.com/patarapolw/zhdiary" } ], - "fullUrl": "https://zhdiary.polvcode.dev" + "fullUrl": "https://zhdiary.polvcode.dev", + "author": { + "name": "Pacharapol Withayasakpunt" + } } \ No newline at end of file diff --git a/data/posts/千字文/千字文1.2.md b/data/posts/千字文/千字文1.2.md index 4e6c4c9..202f179 100644 --- a/data/posts/千字文/千字文1.2.md +++ b/data/posts/千字文/千字文1.2.md @@ -37,13 +37,7 @@ tag: figcaption.text-center zhang1 ``` - - ```css parsed -table td:first-child { - width: 10em; -} - figure { width: 100px; } @@ -55,6 +49,14 @@ figure { } ``` + + +```css parsed +table td:first-child { + width: 10em; +} +``` + 盈利 | yínglì | profit / gain 轻盈 | qīngyíng | graceful / lithe / light and graceful / lighthearted / relaxed 盈亏 | yíngkuī | profit and loss / waxing and waning diff --git a/data/posts/千字文/千字文1.4.md b/data/posts/千字文/千字文1.4.md index 1ba3229..b500acc 100644 --- a/data/posts/千字文/千字文1.4.md +++ b/data/posts/千字文/千字文1.4.md @@ -37,13 +37,7 @@ tag: figcaption.text-center yang2 ``` - - ```css parsed -table td:first-child { - width: 10em; -} - figure { width: 100px; } @@ -55,6 +49,14 @@ figure { } ``` + + +```css parsed +table td:first-child { + width: 10em; +} +``` + 闰年 | rùnnián | leap year / (lunar calendar) year with a thirteen intercalary month 闰月 | rùnyuè | intercalary month in the lunar calendar / leap month 敖闰 | Áorùn | Dragon King of the West Sea, Ao Run, also Ao Ji (敖吉) diff --git a/data/posts/千字文/千字文1.6.md b/data/posts/千字文/千字文1.6.md index fdabfdc..03d3c14 100644 --- a/data/posts/千字文/千字文1.6.md +++ b/data/posts/千字文/千字文1.6.md @@ -37,13 +37,7 @@ tag: figcaption.text-center gang1 ``` - - ```css parsed -table td:first-child { - width: 10em; -} - figure { width: 100px; } @@ -55,6 +49,14 @@ figure { } ``` + + +```css parsed +table td:first-child { + width: 10em; +} +``` + 资金 | zījīn | funds / funding / capital 基金 | jījīn | fund 黄金 (黃金) | huángjīn | gold / golden (opportunity) / prime (time) diff --git a/data/posts/千字文/千字文1.7.md b/data/posts/千字文/千字文1.7.md index f68b9fc..11896d0 100644 --- a/data/posts/千字文/千字文1.7.md +++ b/data/posts/千字文/千字文1.7.md @@ -37,13 +37,7 @@ tag: figcaption.text-center guang1 ``` - - ```css parsed -table td:first-child { - width: 10em; -} - figure { width: 100px; } @@ -55,6 +49,14 @@ figure { } ``` + + +```css parsed +table td:first-child { + width: 10em; +} +``` + 刀剑 (刀劍) | dāojiàn | sword 剑桥 (劍橋) | Jiànqiáo | Cambridge 利剑 (利劍) | lìjiàn | sharp sword diff --git a/data/posts/千字文/千字文1.8.md b/data/posts/千字文/千字文1.8.md index ea1ac6c..b86353d 100644 --- a/data/posts/千字文/千字文1.8.md +++ b/data/posts/千字文/千字文1.8.md @@ -37,13 +37,7 @@ tag: figcaption.text-center jiang1 ``` - - ```css parsed -table td:first-child { - width: 10em; -} - figure { width: 100px; } @@ -55,6 +49,14 @@ figure { } ``` + + +```css parsed +table td:first-child { + width: 10em; +} +``` + 如果 | rúguǒ | if / in case / in the event that 结果 (結果) | jiēguǒ | to bear fruit / CL: 個|个 结果 (結果) | jiéguǒ | outcome / result / conclusion / in the end / as a result / to kill / to dispatch diff --git a/data/posts/千字文/千字文1.9.md b/data/posts/千字文/千字文1.9.md index 811b5e0..a06ffc4 100644 --- a/data/posts/千字文/千字文1.9.md +++ b/data/posts/千字文/千字文1.9.md @@ -37,13 +37,7 @@ tag: figcaption.text-center xiang2 ``` - - ```css parsed -table td:first-child { - width: 10em; -} - figure { width: 100px; } @@ -55,6 +49,14 @@ figure { } ``` + + +```css parsed +table td:first-child { + width: 10em; +} +``` + 海报 (海報) | hǎibào | poster / playbill / notice 海外 | hǎiwài | overseas / abroad 海洋 | hǎiyáng | ocean / CL: 個|个 diff --git a/data/posts/千字文/千字文2.3.md b/data/posts/千字文/千字文2.3.md index 02c9118..8daa99d 100644 --- a/data/posts/千字文/千字文2.3.md +++ b/data/posts/千字文/千字文2.3.md @@ -37,13 +37,7 @@ tag: figcaption.text-center tang2 ``` - - ```css parsed -table td:first-child { - width: 10em; -} - figure { width: 100px; } @@ -55,6 +49,14 @@ figure { } ``` + + +```css parsed +table td:first-child { + width: 10em; +} +``` + 推荐 (推薦) | tuījiàn | to recommend / recommendation 推广 (推廣) | tuīguǎng | to extend / to spread / to popularize / generalization / promotion (of a product etc) 推动 (推動) | tuīdòng | to push (for acceptance of a plan) / to push forward / to promote / to actuate / CL: 個|个 diff --git a/data/posts/千字文/千字文2.7.md b/data/posts/千字文/千字文2.7.md index c67d8ed..446a128 100644 --- a/data/posts/千字文/千字文2.7.md +++ b/data/posts/千字文/千字文2.7.md @@ -37,13 +37,7 @@ tag: figcaption.text-center wang2 ``` - - ```css parsed -table td:first-child { - width: 10em; -} - figure { width: 100px; } @@ -55,6 +49,14 @@ figure { } ``` + + +```css parsed +table td:first-child { + width: 10em; +} +``` + 遐想 | xiáxiǎng | reverie / daydream / to be lost in wild and fanciful thoughts 闻名遐迩 (聞名遐邇) | wénmíngxiá'ěr | to be famous far and wide (idiom) 遐 | xiá | distant / long-lasting / to abandon diff --git a/data/posts/千字文/千字文2.8.md b/data/posts/千字文/千字文2.8.md index 04128c6..d88591e 100644 --- a/data/posts/千字文/千字文2.8.md +++ b/data/posts/千字文/千字文2.8.md @@ -37,13 +37,7 @@ tag: figcaption.text-center chang2 ``` - - ```css parsed -table td:first-child { - width: 10em; -} - figure { width: 100px; } @@ -55,6 +49,14 @@ figure { } ``` + + +```css parsed +table td:first-child { + width: 10em; +} +``` + 鸣 (鳴) | míng | to cry (of birds, animals and insects) 共鸣 (共鳴) | gòngmíng | resonance (physics) / sympathetic response to sth 争鸣 (爭鳴) | zhēngmíng | to contend diff --git a/data/posts/千字文/千字文3.2.md b/data/posts/千字文/千字文3.2.md index 99dd361..367c7ce 100644 --- a/data/posts/千字文/千字文3.2.md +++ b/data/posts/千字文/千字文3.2.md @@ -37,13 +37,7 @@ tag: figcaption.text-center shang1 ``` - - ```css parsed -table td:first-child { - width: 10em; -} - figure { width: 100px; } @@ -55,6 +49,14 @@ figure { } ``` + + +```css parsed +table td:first-child { + width: 10em; +} +``` + 恭喜 | gōngxǐ | congratulations / greetings 恭 | gōng | respectful 恭贺 (恭賀) | gōnghè | to congratulate respectfully / to express good wishes diff --git a/data/posts/千字文/千字文3.3.md b/data/posts/千字文/千字文3.3.md index 36cffcb..5f1dfef 100644 --- a/data/posts/千字文/千字文3.3.md +++ b/data/posts/千字文/千字文3.3.md @@ -37,13 +37,7 @@ tag: figcaption.text-center liang2 ``` - - ```css parsed -table td:first-child { - width: 10em; -} - figure { width: 100px; } @@ -55,6 +49,14 @@ figure { } ``` + + +```css parsed +table td:first-child { + width: 10em; +} +``` + 女性 | nǚxìng | woman / the female sex 女子 | nǚzǐ | woman / female 女孩 | nǚhái | girl / lass diff --git a/web/backend/package.json b/web/backend/package.json index 35a2c4d..f765af4 100644 --- a/web/backend/package.json +++ b/web/backend/package.json @@ -10,6 +10,7 @@ "dependencies": { "@patarapolw/qsearch": "^1.1.1", "cors": "^2.8.5", + "dayjs": "^1.8.21", "express": "^4.17.1", "fast-glob": "^3.2.2", "gray-matter": "^4.0.2", diff --git a/web/backend/scripts/prepare.ts b/web/backend/scripts/prepare.ts index 40f79bb..3008344 100644 --- a/web/backend/scripts/prepare.ts +++ b/web/backend/scripts/prepare.ts @@ -4,6 +4,7 @@ import crypto from 'crypto' import matter from 'gray-matter' import glob from 'fast-glob' import DataStore from 'nedb-promises' +import dayjs from 'dayjs' import MakeHtml from '../src/utils/make-html' @@ -44,6 +45,7 @@ const db = new DataStore('assets/data.nedb') await db.insert({ ...data, + date: formatDate(data.date), filename: f, h, excerpt: computedExcerpt, @@ -64,8 +66,13 @@ const db = new DataStore('assets/data.nedb') computedContent = computedContent.substr(computedExcerpt.length) } + if (data.date) { + console.log(formatDate(data.date)) + } + await db.insert({ ...data, + date: formatDate(data.date), filename: f, h, excerpt: computedExcerpt, @@ -77,3 +84,17 @@ const db = new DataStore('assets/data.nedb') } })) })().catch(console.error) + +const tzOffset = new Date().getTimezoneOffset() + +function formatDate (d?: string | Date) { + if (d) { + if (typeof d === 'string') { + return dayjs(d).toDate() + } else { + return dayjs(d).add(tzOffset, 'minute').toDate() + } + } + + return d +} diff --git a/web/backend/src/api/data.ts b/web/backend/src/api/data.ts index 8045499..a221e34 100644 --- a/web/backend/src/api/data.ts +++ b/web/backend/src/api/data.ts @@ -26,26 +26,29 @@ dataRouter.get('/*', (req, res) => { dataRouter.post('/', async (req, res, next) => { try { - const { q, project, offset, limit } = req.body - let cond = q - if (typeof q === 'string') { + const { q, cond = {}, project, offset, limit } = req.body + const $and = [ + { filename: { $regex: /^posts\// } }, + cond + ] as any[] + + if (q) { const parser = new QSearch({ dialect: 'nedb', schema: { + title: {}, filename: {}, excerpt: {}, date: { type: 'date' } } }) - cond = parser.parse(q) + $and.push(parser.parse(q)) } - const count = await db.count(cond) + const count = await db.count({ $and }) + + let c = db.find({ $and }, project).skip(offset || 0) - let c = db.find(cond).skip(offset || 0) - if (project) { - c = c.projection(project) - } if (limit !== null) { c = c.limit(limit || 5) } diff --git a/web/backend/yarn.lock b/web/backend/yarn.lock index 2f1145c..e037543 100644 --- a/web/backend/yarn.lock +++ b/web/backend/yarn.lock @@ -420,6 +420,11 @@ dateformat@~1.0.4-1.2.3: get-stdin "^4.0.1" meow "^3.3.0" +dayjs@^1.8.21: + version "1.8.21" + resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.8.21.tgz#98299185b72b9b679f31c7ed987b63923c961552" + integrity sha512-1kbWK0hziklUHkGgiKr7xm59KwAg/K3Tp7H/8X+f58DnNCwY3pKYjOCJpIlVs125FRBukGVZdKZojC073D0IeQ== + debounce@^1.0.0: version "1.2.0" resolved "https://registry.yarnpkg.com/debounce/-/debounce-1.2.0.tgz#44a540abc0ea9943018dc0eaa95cce87f65cd131" diff --git a/web/frontend/package.json b/web/frontend/package.json index eb882bc..1724761 100644 --- a/web/frontend/package.json +++ b/web/frontend/package.json @@ -10,6 +10,7 @@ "axios": "^0.19.2", "buefy": "^0.8.12", "core-js": "^3.6.4", + "dayjs": "^1.8.21", "vue": "^2.6.11", "vue-class-component": "^7.2.2", "vue-extend-layout": "^2.0.6", diff --git a/web/frontend/public/index.html b/web/frontend/public/index.html index 3e91c3f..39bdf80 100644 --- a/web/frontend/public/index.html +++ b/web/frontend/public/index.html @@ -5,6 +5,7 @@ + ZhDiary diff --git a/web/frontend/src/App.vue b/web/frontend/src/App.vue index 9dc07c8..e9b712b 100644 --- a/web/frontend/src/App.vue +++ b/web/frontend/src/App.vue @@ -10,4 +10,10 @@ export default { name: 'App', components: { VueExtendLayouts } } - + + + diff --git a/web/frontend/src/assets/.gitkeep b/web/frontend/src/assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/web/frontend/src/assets/logo.png b/web/frontend/src/assets/logo.png deleted file mode 100644 index f3d2503..0000000 Binary files a/web/frontend/src/assets/logo.png and /dev/null differ diff --git a/web/frontend/src/components/HelloWorld.vue b/web/frontend/src/components/HelloWorld.vue deleted file mode 100644 index bf17cf1..0000000 --- a/web/frontend/src/components/HelloWorld.vue +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - diff --git a/web/frontend/src/components/PostHeader.vue b/web/frontend/src/components/PostHeader.vue new file mode 100644 index 0000000..39af601 --- /dev/null +++ b/web/frontend/src/components/PostHeader.vue @@ -0,0 +1,26 @@ + + + diff --git a/web/frontend/src/components/PostTeaser.vue b/web/frontend/src/components/PostTeaser.vue new file mode 100644 index 0000000..e06e8c9 --- /dev/null +++ b/web/frontend/src/components/PostTeaser.vue @@ -0,0 +1,62 @@ + + + + + diff --git a/web/frontend/src/layouts/default.vue b/web/frontend/src/layouts/default.vue index 0fabe8f..d9b26ff 100644 --- a/web/frontend/src/layouts/default.vue +++ b/web/frontend/src/layouts/default.vue @@ -6,7 +6,9 @@ section b-navbar-item(tag="router-link" to="/") h1.bold {{config.banner}} template(slot="start") - b-navbar-item(v-for="t in config.tabs" + b-navbar-item( + v-for="t in config.tabs" + :key="t.name" :tag="t.to ? 'router-link' : 'a'" :href="t.to ? '' : t.url" :to="t.to ? t.to : ''" @@ -20,7 +22,7 @@ section fa(icon="search") section(style="margin-top: 3.25rem") .columns - .column.column.is-10-desktop.is-offset-1-desktop + .column.column.is-three-fifths-desktop.is-offset-one-fifth-desktop router-view @@ -44,7 +46,7 @@ import { normalizeArray } from '../utils' { hid: 'og:url', property: 'og:url', - content: this.fullUrl + content: url }, ] } diff --git a/web/frontend/src/router/index.ts b/web/frontend/src/router/index.ts index 51a9887..3cbbe6a 100644 --- a/web/frontend/src/router/index.ts +++ b/web/frontend/src/router/index.ts @@ -6,10 +6,33 @@ Vue.use(VueRouter) const router = new VueRouter({ mode: 'history', routes: [ + { + path: '/', + component: () => import('../views/QueryView.vue'), + meta: { + layout: 'default' + } + }, { path: '/:page', - alias: '/', - component: () => import('../views/Home.vue') + component: () => import('../views/QueryView.vue'), + meta: { + layout: 'default' + } + }, + { + path: '/tag/:tag', + component: () => import('../views/QueryView.vue'), + meta: { + layout: 'default' + } + }, + { + path: '/tag/:tag/:page', + component: () => import('../views/QueryView.vue'), + meta: { + layout: 'default' + } } ] }) diff --git a/web/frontend/src/utils.ts b/web/frontend/src/utils.ts index 7718848..95efd41 100644 --- a/web/frontend/src/utils.ts +++ b/web/frontend/src/utils.ts @@ -1,3 +1,11 @@ +import axios from 'axios' + export function normalizeArray (a: T | T[]): T | undefined { return Array.isArray(a) ? a[0] : a } + +export const isRendered = !!document.getElementById('app')!.getAttribute('data-server-rendered') + +export const api = axios.create({ + baseURL: isRendered ? '/api' : 'http://localhost:48000/api' +}) diff --git a/web/frontend/src/views/About.vue b/web/frontend/src/views/About.vue deleted file mode 100644 index 3fa2807..0000000 --- a/web/frontend/src/views/About.vue +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/web/frontend/src/views/Home.vue b/web/frontend/src/views/Home.vue deleted file mode 100644 index 8bd6c57..0000000 --- a/web/frontend/src/views/Home.vue +++ /dev/null @@ -1,18 +0,0 @@ - - - diff --git a/web/frontend/src/views/QueryView.vue b/web/frontend/src/views/QueryView.vue new file mode 100644 index 0000000..bd31c34 --- /dev/null +++ b/web/frontend/src/views/QueryView.vue @@ -0,0 +1,109 @@ + + + diff --git a/web/frontend/yarn.lock b/web/frontend/yarn.lock index 723f614..79ea1b4 100644 --- a/web/frontend/yarn.lock +++ b/web/frontend/yarn.lock @@ -2794,6 +2794,11 @@ dashdash@^1.12.0: dependencies: assert-plus "^1.0.0" +dayjs@^1.8.21: + version "1.8.21" + resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.8.21.tgz#98299185b72b9b679f31c7ed987b63923c961552" + integrity sha512-1kbWK0hziklUHkGgiKr7xm59KwAg/K3Tp7H/8X+f58DnNCwY3pKYjOCJpIlVs125FRBukGVZdKZojC073D0IeQ== + de-indent@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/de-indent/-/de-indent-1.0.2.tgz#b2038e846dc33baa5796128d0804b455b8c1e21d"