Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
upgrade to vitepress 1.0 alpha
  • Loading branch information
yyx990803 committed Aug 19, 2022
1 parent f213371 commit d034c84
Show file tree
Hide file tree
Showing 11 changed files with 424 additions and 209 deletions.
2 changes: 1 addition & 1 deletion .vitepress/config.js
Expand Up @@ -33,7 +33,7 @@ export default defineConfig({
],
vite: {
build: {
minify: 'terser'
// minify: 'terser'
}
}
})
59 changes: 32 additions & 27 deletions .vitepress/genFeed.js
@@ -1,8 +1,11 @@
const fs = require('fs')
const path = require('path')
const { Feed } = require('feed')
const { load } = require('./posts.data')
import fs from 'fs'
import path from 'path'
import { Feed } from 'feed'
import postsData from './posts.data.js'
import { fileURLToPath } from 'url'

const url = `https://blog.vuejs.org`
const dirname = path.dirname(fileURLToPath(import.meta.url))

const feed = new Feed({
title: 'The Vue Point',
Expand All @@ -15,29 +18,31 @@ const feed = new Feed({
copyright: 'Copyright (c) 2021-present, Yuxi (Evan) You and blog contributors'
})

load(true).forEach((post) => {
const file = path.resolve(__dirname, `dist${post.href}`)
const rendered = fs.readFileSync(file, 'utf-8')
const content = rendered.match(
/<div [^<>]+?class="prose[^<>]+?>([\s\S]*)<\/div><\/div><footer/
)
postsData.load(true).then((posts) => {
posts.forEach((post) => {
const file = path.resolve(dirname, `dist${post.href}`)
const rendered = fs.readFileSync(file, 'utf-8')
const content = rendered.match(
/<div [^<>]+?class="prose[^<>]+?>([\s\S]*)<\/div><\/div><footer/
)

feed.addItem({
title: post.title,
id: `${url}${post.href}`,
link: `${url}${post.href}`,
description: post.excerpt,
content: content[1],
author: [
{
name: post.data.author,
link: post.data.twitter
? `https://twitter.com/${post.data.twitter}`
: undefined
}
],
date: post.data.date
feed.addItem({
title: post.title,
id: `${url}${post.href}`,
link: `${url}${post.href}`,
description: post.excerpt,
content: content[1],
author: [
{
name: post.data.author,
link: post.data.twitter
? `https://twitter.com/${post.data.twitter}`
: undefined
}
],
date: post.data.date
})
})
})

fs.writeFileSync(path.resolve(__dirname, 'dist/feed.rss'), feed.rss2())
fs.writeFileSync(path.resolve(dirname, 'dist/feed.rss'), feed.rss2())
})
20 changes: 12 additions & 8 deletions .vitepress/posts.data.js
@@ -1,14 +1,18 @@
const fs = require('fs')
const path = require('path')
const matter = require('gray-matter')
const { createMarkdownRenderer } = require('vitepress')
import fs from 'fs'
import path from 'path'
import matter from 'gray-matter'
import { createMarkdownRenderer } from 'vitepress'
import { fileURLToPath } from 'url'

const md = createMarkdownRenderer(process.cwd())
let md

module.exports = {
const dirname = path.dirname(fileURLToPath(import.meta.url))

export default {
watch: '../posts/*.md',
load(asFeed = false) {
const postDir = path.resolve(__dirname, '../posts')
async load(asFeed = false) {
md = md || (await createMarkdownRenderer(process.cwd()))
const postDir = path.resolve(dirname, '../posts')
return fs
.readdirSync(postDir)
.map((file) => getPost(file, postDir, asFeed))
Expand Down
27 changes: 16 additions & 11 deletions .vitepress/theme/Layout.vue
@@ -1,3 +1,15 @@
<script setup>
import { computed } from 'vue'
import { useRoute } from 'vitepress'
import Home from './Home.vue'
import Article from './Article.vue'
import NotFound from './NotFound.vue'
const route = useRoute()
const isIndex = computed(() => route.path.replace(/index.html$/, '') === '/')
const isNotFound = computed(() => route.component === NotFound)
</script>

<template>
<div class="antialiased">
<div class="max-w-3xl mx-auto px-4 sm:px-6 xl:max-w-5xl xl:px-0">
Expand All @@ -20,7 +32,9 @@
><span class="hidden sm:inline">GitHub </span>Source</a
>
<span class="mr-2 ml-2">·</span>
<a class="hover:text-gray-700" href="/feed.rss">RSS<span class="hidden sm:inline"> Feed</span></a>
<a class="hover:text-gray-700" href="/feed.rss"
>RSS<span class="hidden sm:inline"> Feed</span></a
>
<span class="mr-2 ml-2">·</span>
<a
class="hover:text-gray-700"
Expand All @@ -34,17 +48,8 @@
</div>
<main class="max-w-3xl mx-auto px-4 sm:px-6 xl:max-w-5xl xl:px-0">
<Home v-if="isIndex" />
<NotFound v-else-if="isNotFound" />
<Article v-else />
</main>
</div>
</template>

<script setup>
import { computed } from 'vue'
import { useRoute } from 'vitepress'
import Home from './Home.vue'
import Article from './Article.vue'
const route = useRoute()
const isIndex = computed(() => route.path.replace(/index.html$/, '') === '/')
</script>
3 changes: 3 additions & 0 deletions .vitepress/theme/NotFound.vue
@@ -0,0 +1,3 @@
<template>
<h1>Not Found</h1>
</template>
4 changes: 3 additions & 1 deletion .vitepress/theme/index.js
@@ -1,7 +1,9 @@
import './style.css'

import Layout from './Layout.vue'
import NotFound from './NotFound.vue'

export default {
Layout
Layout,
NotFound
}
7 changes: 4 additions & 3 deletions package.json
Expand Up @@ -2,18 +2,19 @@
"name": "vue-blog",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vitepress",
"build": "vitepress build && node ./.vitepress/genFeed",
"serve": "vitepress serve"
},
"devDependencies": {
"@tailwindcss/typography": "^0.5.0",
"@tailwindcss/typography": "^0.5.4",
"feed": "^4.2.1",
"gray-matter": "^4.0.2",
"vitepress": "^0.21.6"
"vitepress": "^1.0.0-alpha.8"
},
"dependencies": {
"tailwindcss": "^3.0.2"
"tailwindcss": "^3.1.8"
}
}

0 comments on commit d034c84

Please sign in to comment.