Skip to content

Commit

Permalink
feat: support blog (#84)
Browse files Browse the repository at this point in the history
* stage: support blog

* tweaks

* refactor: mv blog posts to blog repo
  • Loading branch information
northword authored Aug 4, 2024
1 parent 9087914 commit 88adb25
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
[submodule "src/styles/detail"]
path = src/styles/detail
url = https://github.com/zotero-chinese/styles.git
[submodule "src/blog/blog-repo"]
path = src/blog/blog-repo
url = https://github.com/zotero-chinese/blog.git
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
// },
"markdown.updateLinksOnFileMove.enabled": "always",
"markdown.editor.pasteUrlAsFormattedLink.enabled": "smart",
"markdownlint.config": {
"MD025": {
"front_matter_title": ""
}
},

/** 文件管理器相关 */
// "explorer.sortOrder": "mixed",
Expand Down
3 changes: 2 additions & 1 deletion src/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ export default defineConfig({
description: 'Zotero 非官方中文维护小组',
lang: 'zh-CN',

srcExclude: ['wiki/index.md', '**/README.md'],
srcExclude: ['wiki/index.md', '**/README.md', '**/_template.md'],
// outDir: 'dist',

rewrites: {
'wiki/:id+': ':id+',
'styles/detail/src/:id+': 'styles/:id+',
'blog/blog-repo/posts/:id+': 'blog/posts/:id+',
},
cleanUrls: true,

Expand Down
1 change: 1 addition & 0 deletions src/.vitepress/config/navbar.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const nav: DefaultTheme.NavItem[] = [
{
text: '社区',
items: [
{ text: '博客', link: '/blog/' },
{ text: '关于我们', link: '/about' },
{ text: '贡献者名单', link: '/contributors' },
{ text: '贡献指南', link: '/contributing/' },
Expand Down
1 change: 1 addition & 0 deletions src/.vitepress/config/sidebar.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const sidebar: DefaultTheme.Sidebar = {
// "/styles/detail/": (() => {
// return [];
// })(),
'/blog/': [],
'/': [
{ text: '关于我们', link: '/about' },
{ text: '贡献者名单', link: '/contributors' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ interface Post {
declare const data: Post[]
export { data }

export default createContentLoader('blog/*.md', {
export default createContentLoader('blog/blog-repo/posts/!(_template|index).md', {
// excerpt: true,
transform(raw): Post[] {
return raw
.filter(({ frontmatter }) => !frontmatter.draft)
.map(({ url, frontmatter }) => ({
title: frontmatter.head.find(e => e[1].property === 'og:title')[1]
.content,
title: frontmatter.title,
url,
date: formatDate(frontmatter.date),
}))
Expand Down
37 changes: 23 additions & 14 deletions src/.vitepress/theme/components/BlogIndex.vue
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
<script setup lang="ts">
import { data as posts } from './blog.data'
import { data as posts } from '@data/blog.data'
function getDateTime(time: number) {
return new Date(time).toISOString()
}
</script>

<template>
<ul class="blog-list">
<li v-for="post of posts" :key="post.url" class="blog-entry">
<article>
<time :datetime="getDateTime(post.date.time)">
{{ post.date.string }}
</time>
<h2 class="title">
<a :href="post.url">{{ post.title }}</a>
</h2>
</article>
</li>
</ul>
<div class="blog-list-warpper vp-doc">
<ul v-if="posts.length !== 0" class="blog-list">
<li v-for="post of posts" :key="post.url" class="blog-entry">
<article>
<time :datetime="getDateTime(post.date.time)">
{{ post.date.string }}
</time>
<h2 class="title">
<a :href="post.url">{{ post.title }}</a>
</h2>
</article>
</li>
</ul>

<el-empty v-else description="暂无内容" />
</div>
</template>

<style scoped>
.blog-list {
list-style-type: none;
padding: 0;
padding: 0 20% 5em 20%;
}
@media only screen and (max-width: 800px) {
.blog-list {
padding: 0;
}
}
.blog-entry {
margin-top: 3em;
Expand Down
11 changes: 8 additions & 3 deletions src/.vitepress/theme/components/Market.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { useData } from 'vitepress'
import { defineAsyncComponent } from 'vue'
import { computed, defineAsyncComponent } from 'vue'
// @ts-expect-error data 是 vitepress 的隐式导出
import { data as _pluginUpdateTime } from '@data/update-time.data'
Expand All @@ -10,7 +10,8 @@ import MarketHero from './MarketHero.vue'
import Loading from './Loading.vue'
const { frontmatter } = useData()
const updateTime = frontmatter.value.type === 'plugin' ? _pluginUpdateTime.lastUpdate : _updateTime
const updateTime = computed(() => frontmatter.value.type === 'plugin' ? _pluginUpdateTime.lastUpdate : _updateTime)
const description = computed(() => frontmatter.value.description ?? `更新时间:${updateTime.value}`)
const PluginCards = defineAsyncComponent(() =>
import('./PluginCards.vue'))
Expand All @@ -20,6 +21,8 @@ const StyleCards = defineAsyncComponent(() =>
import('./StyleCards.vue'))
const TranslatorCards = defineAsyncComponent(() =>
import('./TranslatorCards.vue'))
const BlogIndex = defineAsyncComponent(() =>
import('./BlogIndex.vue'))
function getComponentByType(type: string) {
switch (type) {
Expand All @@ -31,6 +34,8 @@ function getComponentByType(type: string) {
return StyleCards
case 'translator':
return TranslatorCards
case 'blog':
return BlogIndex
default:
return null
}
Expand All @@ -41,7 +46,7 @@ function getComponentByType(type: string) {
<div class="VPPage Market">
<MarketHero
:title="frontmatter.title"
:description="`更新时间:${updateTime}`"
:description="description"
:actions="frontmatter.actions"
/>
<main class="MarketMain">
Expand Down
1 change: 1 addition & 0 deletions src/blog/blog-repo
Submodule blog-repo added at dafe3e
15 changes: 15 additions & 0 deletions src/blog/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
layout: Market
type: blog
title: 社区博客
description: 获取 Zotero 中文社区的最近动态
sidebar: false
editLink: false
outline: false
aside: false
comments: false
prev: false
next: false
---

<!-- markdownlint-disable -->

0 comments on commit 88adb25

Please sign in to comment.