Skip to content

Commit

Permalink
feat(zhi-blog-nuxt): add nuxt blog
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed May 6, 2023
1 parent aa6f15d commit a202629
Show file tree
Hide file tree
Showing 12 changed files with 1,443 additions and 22 deletions.
2 changes: 1 addition & 1 deletion apps/zhi-blog-nuxt/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default defineAppConfig({
},
],
sidebarDepth: 2, // 侧边栏显示深度,默认1,最大2(显示到h3标题)
logo: "/img/logo-small.png", // 导航栏logo
logo: "img/logo-small.png", // 导航栏logo
repo: "terwer/zhi", // 导航栏右侧生成Github链接
// repo: "https://gitee.com/terwer/zhi",
repoLabel: undefined,
Expand Down
5 changes: 4 additions & 1 deletion apps/zhi-blog-nuxt/components/vdoing/BodyBgImg.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ZhiBlogNuxtUtil.initEnv(env)
// datas
const datas = reactive({
appBase: window.location.origin + env.getStringEnv("VITE_APP_BASE"),
appBase: env.getStringEnv("VITE_APP_BASE"),
bgImg: "",
opacity: 0.5,
})
Expand All @@ -39,6 +39,9 @@ const methods = {
}
// lifecycle
onBeforeMount(() => {
datas.appBase = window.location.origin + env.getStringEnv("VITE_APP_BASE")
})
onMounted(() => {
const { bodyBgImg, bodyBgImgOpacity, bodyBgImgInterval = 15 } = appConfig.themeConfig
Expand Down
4 changes: 4 additions & 0 deletions apps/zhi-blog-nuxt/components/vdoing/MeiliSearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
import { AisInstantSearch, AisHits, AisSearchBox } from "vue-instantsearch/vue3/es"
const client = useMeilisearchClient()
// lifecycle
onBeforeMount(() => {
})
</script>

<style lang="stylus" scoped>
Expand Down
7 changes: 6 additions & 1 deletion apps/zhi-blog-nuxt/components/vdoing/NavLinks.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<nav v-if="computes.userLinks.value.length || computes.repoLink.value" class="nav-links">
<!-- user links -->
<div v-for="item in computes.userLinks.value" :key="item.link" class="nav-item">
<div v-for="item in computes.userLinks.value" :key="item.link + props.sign" class="nav-item">
<DropdownLink v-if="item.type === 'links'" :item="item" />
<NavLink v-else :item="item" />
</div>
Expand Down Expand Up @@ -35,6 +35,11 @@ const logger = ZhiBlogNuxtUtil.zhiLog("nav-links")
const appConfig = useAppConfig()
// props
const props = defineProps({
sign: String,
})
const computes = {
nav: computed(() => {
// const { locales } = this.$site
Expand Down
7 changes: 3 additions & 4 deletions apps/zhi-blog-nuxt/components/vdoing/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@

<div class="links" :style="datas.linksWrapMaxWidth ? { 'max-width': datas.linksWrapMaxWidth + 'px' } : {}">
<MeiliSearchBox v-if="computes.isMeilisearch" />
<client-only v-if="!datas.isMobile">
<NavLinks class="can-hide" />
</client-only>
<NavLinks class="can-hide" sign="pc"/>
</div>
</header>
</template>
Expand All @@ -42,7 +40,7 @@ ZhiBlogNuxtUtil.initEnv(env)
// datas
const datas = reactive({
appBase: window.location.origin + env.getStringEnv("VITE_APP_BASE"),
appBase: env.getStringEnv("VITE_APP_BASE"),
isMobile: true,
linksWrapMaxWidth: null,
})
Expand All @@ -61,6 +59,7 @@ const computes = {
// lifecycle
onBeforeMount(async () => {
datas.appBase = window.location.origin + env.getStringEnv("VITE_APP_BASE")
// const deviceDetector = await import("next-vue-device-detector")
// const d = deviceDetector.createDeviceDetector()
// datas.isMobile = d.mobile
Expand Down
11 changes: 7 additions & 4 deletions apps/zhi-blog-nuxt/components/vdoing/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
</div>

<!-- 移动端Nav -->
<client-only v-if="datas.isMobile">
<NavLinks />
</client-only>
<!-- <NavLinks sign="mobile"/>-->

<!--
<slot name="top" />
-->

<!--
<SidebarLinks :depth="0" :items="props.items" />
Expand Down Expand Up @@ -55,7 +56,7 @@ const props = defineProps({
// datas
const datas = reactive({
appBase: window.location.origin + env.getStringEnv("VITE_APP_BASE"),
appBase: env.getStringEnv("VITE_APP_BASE"),
isMobile: false,
})
Expand All @@ -68,6 +69,8 @@ const computes = {
// lifecycle
onBeforeMount(async () => {
datas.appBase = window.location.origin + env.getStringEnv("VITE_APP_BASE")
// const deviceDetector = await import("next-vue-device-detector")
// const d = deviceDetector.createDeviceDetector()
// datas.isMobile = d.mobile
Expand Down
103 changes: 102 additions & 1 deletion apps/zhi-blog-nuxt/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,105 @@
const isDev = process.env.NODE_ENV === "development"
const isSiyuanBuild = process.env.BUILD_TYPE === "siyuan"
const isVercelBuild = process.env.BUILD_TYPE === "vercel"

const appBase = isSiyuanBuild
? "/appearance/themes/zhi/web/blog/"
: isDev || isVercelBuild
? "/"
: "/zhi/apps/zhi-web-blog/dist/"
const distDir = isSiyuanBuild
? "/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/web/blog"
: "./dist"
const isSsr = isDev || isVercelBuild
// const ssrPreset = isVercelBuild ? "vercel" : isDev ? "node-server" : undefined
// const ssrServeStatic = isSiyuanBuild
const staticV = "202304191333"

console.log("isDev=>", isDev)
console.log("appBase=>", appBase)
console.log("isSiyuanBuild=>", isSiyuanBuild)
console.log("isVercelBuild=>", isVercelBuild)
console.log("isSsr=>", isSsr)
// console.log("ssrPreset=>", ssrPreset)
// console.log("ssrServeStatic=>", ssrServeStatic)

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
// content
// https://content.nuxtjs.org/guide/writing/content-directory

// meilisearch
// https://github.com/xlanex6/nuxt-meilisearch
// https://docs.meilisearch.com/learn/getting_started/quick_start.html

});
modules: ["@nuxt/content", "nuxt-meilisearch"],
content: {
// https://content.nuxtjs.org/api/configuration
},
app: {
baseURL: appBase,
head: {
charset: "utf-8",
viewport: "width=device-width, initial-scale=1",
link: [{ rel: "stylesheet", href: appBase + "lib/webfont/webfont.css?v=" + staticV }],
// script: [
// {
// src: appBase + "lib/lute/lute-1.7.5-20230410.min.js?v=" + staticV,
// body: true,
// },
// ],
},
},
css: ["~/assets/vdoing/styles/index.styl"],
runtimeConfig: {
// default type
VITE_DEFAULT_TYPE: "siyuan",
// siyuan
VITE_SIYUAN_API_URL: "",
VITE_SIYUAN_AUTH_TOKEN: "",
// WordPress
VITE_WORDPRESS_API_URL: "",
VITE_WORDPRESS_USERNAME: "",
VITE_WORDPRESS_PASSWORD: "",
public: {
VITE_STATIC_VERSION: staticV,
VITE_APP_BASE: appBase,
VITE_LOG_LEVEL: "INFO",
VITE_DEBUG_MODE: false,
// 保证思源笔记内部在 SPA 的情况下默认可用
VITE_SIYUAN_API_URL: "",
},
},
ssr: isSsr,
// https://nuxt.com/docs/guide/going-further/custom-routing#hash-mode-spa
router: {
options: {
hashMode: true,
},
},
nitro: {
output: {
publicDir: distDir,
},
// preset: ssrPreset,
// // 开启之后将进行静态伺服
// serveStatic: ssrServeStatic,
},
meilisearch: {
hostUrl: process.env.MEILISEARCH_ENDPOINT ?? "http://localhost:3000/api/endpoint/meilisearch",
// /Users/terwer/Documents/code/meilisearch/meilisearch-macos-amd64
// hostUrl: "http://localhost:7700",
searchApiKey: "<your_search_key>",
adminApiKey: "<your_admin_key>",
instantSearch: true, // default true
serverSideUsage: true, // default false
// optional
clientOptions: {
placeholderSearch: true, // default
paginationTotalHits: 50, // default
finitePagination: true, // default
primaryKey: undefined, // default
keepZeroFacets: false, // default
},
},
})
6 changes: 4 additions & 2 deletions apps/zhi-blog-nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
"devDependencies": {
"@types/good-storage": "^1.1.0",
"@types/node": "^18",
"@nuxt/content": "^2.5.2",
"consola": "^3.0.1",
"nuxt": "^3.4.3",
"nuxt-meilisearch": "^0.1.7"
},
"dependencies": {
"@siyuan-community/zhi-common": "*",
"@siyuan-community/zhi-env": "*",
"@siyuan-community/zhi-common": "1.6.3",
"@siyuan-community/zhi-env": "1.14.1",
"@types/lodash": "^4.14.194",
"good-storage": "^1.1.1",
"lodash": "^4.17.21",
Expand Down
34 changes: 34 additions & 0 deletions apps/zhi-blog-nuxt/pages/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!--
- Copyright (c) 2023, Terwer . All rights reserved.
- DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-
- This code is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License version 2 only, as
- published by the Free Software Foundation. Terwer designates this
- particular file as subject to the "Classpath" exception as provided
- by Terwer in the LICENSE file that accompanied this code.
-
- This code is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- version 2 for more details (a copy is included in the LICENSE file that
- accompanied this code).
-
- You should have received a copy of the GNU General Public License version
- 2 along with this work; if not, write to the Free Software Foundation,
- Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-
- Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com
- or visit www.terwer.space if you need additional information or have any
- questions.
-->

<template>
<div>
<!-- <div v-for="post in testPosts.posts">-->
<h1>1111
<!-- <NuxtLink :to="'/post/' + post.postid"> {{ post.title }} </NuxtLink>-->
</h1>
<!-- </div>-->
</div>
</template>
Loading

0 comments on commit a202629

Please sign in to comment.