netlify is more reliable
This commit is contained in:
1 parent
7fe8f5d154
commit
4dfff986d4
16 files changed
+42
-105
No files matched your search
@@ -1,5 +1,8 @@
|
||||
import QParser from 'q2filter'
|
||||
|
||||
export const TAGS = JSON.parse(process.env.tags!)
|
||||
export const HASH = JSON.parse(process.env.hash!)
|
||||
|
||||
export function escapeRegExp (s: string) {
|
||||
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') // $& means the whole matched string
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import PostHeader from './PostHeader.vue'
|
||||
import Empty from './Empty.vue'
|
||||
import { Vue, Component, Prop, Watch } from 'nuxt-property-decorator'
|
||||
import { makeHtml } from '../assets/make-html'
|
||||
import { globalStore } from '../store'
|
||||
import { HASH } from '../assets/util'
|
||||
|
||||
@Component({
|
||||
components: {
|
||||
@@ -44,9 +44,9 @@ export default class PostFull extends Vue {
|
||||
@Watch('header.path')
|
||||
async updatePost () {
|
||||
if (!this.markdown) {
|
||||
this.markdown = await fetch(`/build/teaser/${this.header.path}?h=${globalStore.hash.posts[this.header.path]}`).then((r) => r.text())
|
||||
this.markdown = await fetch(`/build/teaser/${this.header.path}?h=${HASH.posts[this.header.path]}`).then((r) => r.text())
|
||||
}
|
||||
this.markdown = await fetch(`/build/full/${this.header.path}?h=${globalStore.hash.posts[this.header.path]}`).then((r) => r.text())
|
||||
this.markdown = await fetch(`/build/full/${this.header.path}?h=${HASH.posts[this.header.path]}`).then((r) => r.text())
|
||||
}
|
||||
|
||||
get html () {
|
||||
|
||||
@@ -17,9 +17,8 @@ section
|
||||
import PostTeaser from './PostTeaser.vue'
|
||||
import Empty from './Empty.vue'
|
||||
import QParser from 'q2filter'
|
||||
import { normalizeArray, searchPosts } from '@/assets/util'
|
||||
import { normalizeArray, searchPosts, HASH } from '@/assets/util'
|
||||
import { Vue, Component, Prop, Watch } from 'nuxt-property-decorator'
|
||||
import { globalStore } from '../store'
|
||||
|
||||
@Component({
|
||||
components: {
|
||||
@@ -70,10 +69,10 @@ export default class PostQuery extends Vue {
|
||||
tag: this.tag,
|
||||
} : this.q,
|
||||
current: true,
|
||||
posts: await fetch(`/build/header/posts.json?h=${globalStore.hash.posts._header}`).then((r) => r.json()),
|
||||
posts: await fetch(`/build/header/posts.json?h=${HASH.posts._header}`).then((r) => r.json()),
|
||||
}).map(async (h) => {
|
||||
if (!h.teaser) {
|
||||
h.teaser = await fetch(`/build/teaser/${h.path}?h=${globalStore.hash.posts[h.path]}`).then((r) => r.text())
|
||||
h.teaser = await fetch(`/build/teaser/${h.path}?h=${HASH.posts[h.path]}`).then((r) => r.text())
|
||||
}
|
||||
return h
|
||||
}))
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
import PostHeader from './PostHeader.vue'
|
||||
import { Vue, Component, Prop } from 'nuxt-property-decorator'
|
||||
import { makeHtml } from '../assets/make-html'
|
||||
import { globalStore } from '../store'
|
||||
import { HASH } from '../assets/util'
|
||||
|
||||
@Component({
|
||||
components: {
|
||||
@@ -29,7 +29,7 @@ export default class PostTeaser extends Vue {
|
||||
|
||||
async mounted () {
|
||||
if (!this.teaser) {
|
||||
this.teaser = await fetch(`/build/teaser/${this.header.path}.html?h=${globalStore.hash.posts[this.header.path]}`)
|
||||
this.teaser = await fetch(`/build/teaser/${this.header.path}.html?h=${HASH.posts[this.header.path]}`)
|
||||
.then((r) => r.text())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,8 +33,7 @@ section
|
||||
<script lang="ts">
|
||||
import PageSocial from '@/components/PageSocial.vue'
|
||||
import { Vue, Component } from 'nuxt-property-decorator'
|
||||
import { normalizeArray } from '@/assets/util'
|
||||
import { globalStore } from '~/store'
|
||||
import { normalizeArray, TAGS } from '@/assets/util'
|
||||
|
||||
@Component
|
||||
export default class Default extends Vue {
|
||||
@@ -53,7 +52,7 @@ export default class Default extends Vue {
|
||||
q = ''
|
||||
|
||||
get tags () {
|
||||
const tagList = globalStore.tag
|
||||
const tagList = TAGS
|
||||
|
||||
return Object.keys(tagList).sort((a, b) => {
|
||||
return tagList[b] - tagList[a]
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"name": "zhdiary",
|
||||
"version": 2,
|
||||
"builds": [
|
||||
{
|
||||
"src": "nuxt.config.ts",
|
||||
"use": "@nuxtjs/now-builder",
|
||||
"config": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
import { Configuration } from '@nuxt/types'
|
||||
import tag from './static/build/tag/posts.json'
|
||||
import posts from './static/build/header/posts.json'
|
||||
|
||||
const config: Configuration = {
|
||||
mode: 'universal',
|
||||
@@ -90,8 +92,22 @@ const config: Configuration = {
|
||||
})
|
||||
},
|
||||
},
|
||||
generate: {
|
||||
routes: [
|
||||
...Object.keys(tag).map((el) => `/tag/${el}`),
|
||||
...Object.values(posts).map((el) => {
|
||||
return el.y && el.mo ? `/post/${el.y}/${el.mo}/${el.name}` : `/post/${el.name}`
|
||||
}),
|
||||
],
|
||||
fallback: true,
|
||||
},
|
||||
env: {
|
||||
title: '中文 Diary',
|
||||
tags: JSON.stringify(tag),
|
||||
hash: JSON.stringify({
|
||||
posts: require('./static/build/hash/posts.json'),
|
||||
slides: require('./static/build/hash/slides.json'),
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,10 @@
|
||||
"build": "nuxt-ts build",
|
||||
"generate": "nuxt-ts generate",
|
||||
"start": "nuxt-ts start",
|
||||
"prebuild": "ts-node -O '{\"module\": \"commonjs\"}' utils/build-api.ts"
|
||||
"build-api": "ts-node -O '{\"module\": \"commonjs\"}' utils/build-api.ts",
|
||||
"prebuild": "yarn build-api",
|
||||
"pregenerate": "yarn build-api",
|
||||
"deploy": "yarn generate && netlify deploy --dir dist"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fortawesome/fontawesome-svg-core": "^1.2.26",
|
||||
|
||||
@@ -6,9 +6,8 @@ post-full(:header="header")
|
||||
import { Vue, Component } from 'nuxt-property-decorator'
|
||||
import PostFull from '@/components/PostFull.vue'
|
||||
import htmlToText from 'html-to-text'
|
||||
import { apiHash } from '@/assets/util'
|
||||
import { apiHash, HASH } from '@/assets/util'
|
||||
import MakeHtml from '@/assets/make-html'
|
||||
import { globalStore } from '../../store'
|
||||
|
||||
@Component({
|
||||
components: {
|
||||
@@ -19,11 +18,7 @@ export default class PostPage extends Vue {
|
||||
header: any = {}
|
||||
|
||||
async asyncData ({ params, error, redirect }: any) {
|
||||
// if(process.static && process.client && $payloadURL) {
|
||||
// return await $axios.$get($payloadURL(route))
|
||||
// }
|
||||
|
||||
const ps: any[] = JSON.parse(await apiHash('/build/header/posts.json', globalStore.hash.posts._header))
|
||||
const ps: any[] = JSON.parse(await apiHash('/build/header/posts.json', HASH.posts._header))
|
||||
const header = ps.filter((p) => p.name === params.name)[0]
|
||||
|
||||
if (!header) {
|
||||
@@ -34,7 +29,7 @@ export default class PostPage extends Vue {
|
||||
return redirect(encodeURI(`/post/${header.y}/${header.mo}/${params.name}`))
|
||||
}
|
||||
|
||||
header.teaser = await apiHash(`/build/teaser/${header.path}`, globalStore.hash.posts[header.path])
|
||||
header.teaser = await apiHash(`/build/teaser/${header.path}`, HASH.posts[header.path])
|
||||
|
||||
return {
|
||||
header,
|
||||
|
||||
@@ -9,7 +9,7 @@ div(style="width: 100vw; height: 100vh")
|
||||
import { Vue, Component } from 'nuxt-property-decorator'
|
||||
import MakeHtml from '@/assets/make-html'
|
||||
import matter from 'gray-matter'
|
||||
import { apiHash } from '@/assets/util'
|
||||
import { apiHash, HASH } from '@/assets/util'
|
||||
// @ts-ignore
|
||||
import shortHash from 'short-hash'
|
||||
import $ from 'cheerio'
|
||||
@@ -18,7 +18,6 @@ import scopeCss from 'scope-css'
|
||||
import h from 'hyperscript'
|
||||
import qs from 'querystring'
|
||||
import stringify from 'fast-json-stable-stringify'
|
||||
import { globalStore } from '../store'
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
@@ -61,7 +60,7 @@ export default class RevealMd extends Vue {
|
||||
|
||||
if (path) {
|
||||
try {
|
||||
const raw = await apiHash(`/build/slides/${path}`, globalStore.hash.slides[path as string])
|
||||
const raw = await apiHash(`/build/slides/${path}`, HASH.slides[path as string])
|
||||
const { data, content } = matter(raw)
|
||||
|
||||
return {
|
||||
@@ -106,7 +105,7 @@ export default class RevealMd extends Vue {
|
||||
const { path } = this.$route.query
|
||||
if (!this.defaults.markdown && path) {
|
||||
try {
|
||||
const raw = await apiHash(`/build/slides/${path}`, globalStore.hash.slides[path as string])
|
||||
const raw = await apiHash(`/build/slides/${path}`, HASH.slides[path as string])
|
||||
const { data, content } = matter(raw)
|
||||
|
||||
this.defaults.markdown = content
|
||||
|
||||
Whitespace-only changes.
@@ -1,26 +0,0 @@
|
||||
import { Module, VuexModule, Mutation } from 'vuex-module-decorators'
|
||||
import { DataType } from '../utils/build-api'
|
||||
|
||||
@Module({
|
||||
name: 'global',
|
||||
stateFactory: true,
|
||||
namespaced: true,
|
||||
})
|
||||
export default class GlobalModule extends VuexModule {
|
||||
hash: Record<DataType, Record<string, string>> = {
|
||||
posts: {},
|
||||
slides: {},
|
||||
}
|
||||
|
||||
tag: Record<string, number> = {}
|
||||
|
||||
@Mutation
|
||||
setHash (h: any) {
|
||||
this.hash = h
|
||||
}
|
||||
|
||||
@Mutation
|
||||
setTag (tag: any) {
|
||||
this.tag = tag
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
import { Store, ActionTree } from 'vuex'
|
||||
import { initialiseStores } from '~/utils/store-accessor'
|
||||
import { apiHash } from '~/assets/util'
|
||||
|
||||
const initializer = (store: Store<any>) => initialiseStores(store)
|
||||
|
||||
export const actions: ActionTree<any, any> = {
|
||||
async nuxtServerInit ({ commit }) {
|
||||
const [
|
||||
hPosts,
|
||||
hSlides,
|
||||
tPosts,
|
||||
] = await Promise.all([
|
||||
apiHash('/build/hash/posts.json', Math.random().toString().substr(-5)),
|
||||
apiHash('/build/hash/slides.json', Math.random().toString().substr(-5)),
|
||||
apiHash('/build/tag/posts.json', Math.random().toString().substr(-5)),
|
||||
])
|
||||
|
||||
commit('global/setHash', {
|
||||
posts: JSON.parse(hPosts),
|
||||
slides: JSON.parse(hSlides),
|
||||
})
|
||||
commit('global/setTag', JSON.parse(tPosts))
|
||||
},
|
||||
}
|
||||
|
||||
export const plugins = [initializer]
|
||||
export * from '~/utils/store-accessor'
|
||||
@@ -15,6 +15,7 @@
|
||||
"noEmit": true,
|
||||
"experimentalDecorators": true,
|
||||
"skipLibCheck": true,
|
||||
"resolveJsonModule": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"~/*": [
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
import { Store } from 'vuex'
|
||||
import { getModule } from 'vuex-module-decorators'
|
||||
import GlobalModule from '../store/global'
|
||||
|
||||
let globalStore: GlobalModule
|
||||
|
||||
function initialiseStores (store: Store<any>): void {
|
||||
globalStore = getModule(GlobalModule, store)
|
||||
}
|
||||
|
||||
export {
|
||||
initialiseStores,
|
||||
globalStore,
|
||||
}
|
||||
Reference in new issue
Block a user