Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 3ed03f9
Author: Thaumy <[email protected]>
Date:   Wed Jan 4 17:09:45 2023 +0800

    add compile time config
  • Loading branch information
Thaumy committed Jan 4, 2023
1 parent 11e532d commit e9ac8c4
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 38 deletions.
2 changes: 2 additions & 0 deletions app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import FixedBtnZone from "@/components/common/FixedBtnZone.vue"
import {useTheme} from "vuetify"
import {addRouteMiddleware, useAsyncData, useNuxtApp, useRoute, useRouter, useState} from "#app"
import {Tab} from "~/components/field/type"
import build_meta from "~/field.meta"
const route = useRoute()
const router = useRouter()
Expand All @@ -61,6 +62,7 @@ addRouteMiddleware(async (to, from) => {
})
onBeforeMount(() => {
document.body.style.backgroundImage = `url('${build_meta.backgroundImgUrl}')`
provide('isDarkTheme', useTheme().global.current.value.dark)
})
Expand Down
9 changes: 5 additions & 4 deletions components/Menu/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
/>
<Avatar
:about_me_post_id="about_me_post_id"
:avatar-url="avatar_img_url"
:avatar-url="build_meta.avatarImgUrl"
/>
<Info
class="mb-4"
title="THAUMY的小站"
:title=build_meta.siteTitle
:typing="[
'你好!~~^400',
'这里是THAUMY的博客!^300',
Expand All @@ -37,8 +37,9 @@
</f-tabs>

<About
v-ripple
:about_site_post_id="about_site_post_id"
info="Thaumy's Blog©2016-2023<br>About Site" v-ripple
info="Thaumy's Blog©2016-2023<br>About Site"
/>

</f-card>
Expand All @@ -56,7 +57,7 @@ import FTab from "@/components/field/f-tab.vue"
import FTabs from "@/components/field/f-tabs.vue"
import FCard from "@/components/field/f-card.vue"
import ThemeToggleBtn from "@/components/btn/ThemeToggleBtn.vue"
import {avatar_img_url} from "@/public/config/site"
import build_meta from "~/field.meta"
import {useRouter, useRoute} from "#app"
const props =
Expand Down
9 changes: 4 additions & 5 deletions components/MenuBar/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
<div class="cursor-pointer flex">
<img
class="avatar border-shadow"
:src="avatar_img_url" alt="avatar"
:src="build_meta.avatarImgUrl" alt="avatar"
@click="router.push('/'+about_me_post_id)"
/>
<div
class="name"
@click="router.push('/')"
>
THAUMY的小站
</div>
v-text=build_meta.siteTitle
/>
</div>

<transition name="open-drawer-btn">
Expand Down Expand Up @@ -50,8 +49,8 @@ import {makeDebounce} from "@/scripts/util/debounce"
import Drawer from "./Drawer.vue"
import {Tab} from "@/components/field/type"
import Shadow from "@/components/MenuBar/Shadow.vue"
import {avatar_img_url} from "@/public/config/site"
import {useRouter} from "#app"
import build_meta from "~/field.meta"
const router = useRouter()
Expand Down
35 changes: 35 additions & 0 deletions field.meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class BuildMeta {
//config Field here
#site_title = 'THAUMY的小站'
#site_icon_url = 'https://cdn.thaumy.cn/ui/icon.png'
#enable_cdn = false
#cdn_url = 'https://cdn.thaumy.cn'

#avatar_img_url = 'https://cdn.thaumy.cn/ui/avatar.png'
#background_img_url = 'https://cdn.thaumy.cn/ui/background.jpg'

#ws_server_root = 'ws://127.0.0.1:10010'
#ws_client_root = 'ws://127.0.0.1:10011'
//#ws_client_root = 'wss://next.thaumy.cn:10011'

#enable_server_dev_log = true
#enable_client_dev_log = true


//public fields
siteTitle = this.#site_title
siteIconUrl = this.#site_icon_url
cdnURL = this.#enable_cdn ? this.#cdn_url : ''

avatarImgUrl = this.#avatar_img_url
backgroundImgUrl = this.#background_img_url

wsServerRoot = this.#ws_server_root
wsClientRoot = this.#ws_client_root

enableServerDevLog = this.#enable_server_dev_log
enableClientDevLog = this.#enable_client_dev_log
}

export default new BuildMeta()

9 changes: 4 additions & 5 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import vuetify from "vite-plugin-vuetify"
import prismjsPlugin from "vite-plugin-prismjs"
import build_meta from './field.meta'

export default defineNuxtConfig({
typescript: {
Expand All @@ -17,12 +18,11 @@ export default defineNuxtConfig({
}
},
app: {
//config CDN here
cdnURL: 'https://cdn.thaumy.cn',
cdnURL: build_meta.cdnURL,
head: {
title: 'THAUMY的博客',
title: build_meta.siteTitle,
link: [
{rel: 'icon', href: 'https://cdn.thaumy.cn/ui/icon.png'}
{rel: 'icon', href: build_meta.siteIconUrl}
],
script: [
{src: './config/mathjax.js'},
Expand Down Expand Up @@ -74,7 +74,6 @@ export default defineNuxtConfig({
'python', 'fsharp', 'scheme', 'kotlin',
'haskell',
'javascript', 'typescript',
//rare usage
'idris', 'less', 'lisp', 'agda', 'racket', 'julia', 'graphql', 'http', 'lua'
]
//TODO fix style
Expand Down
2 changes: 2 additions & 0 deletions public/config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
6 changes: 0 additions & 6 deletions public/config/site.ts

This file was deleted.

File renamed without changes.
2 changes: 0 additions & 2 deletions styles/global/tag.styl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ body
background-size cover
background-position center
background-attachment fixed
//background-image url("@/public/background.jpg")
background-image url("https://cdn.thaumy.cn/ui/background.jpg")

.v-application
background unset !important
15 changes: 9 additions & 6 deletions ws/client/helper.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {randomId, reqStringify, rspParse} from "@/ws/helper"
import {ApiRequest, ApiResponse} from "@/ws/helper"
import {wsClientRoot} from "~/ws/meta"
import build_meta from "~/field.meta"

export {
makeWebSocket,
makeHandler
}

function makeWebSocket(api_path: string) {
return new WebSocket(`${wsClientRoot}${api_path}`)
return new WebSocket(`${build_meta.wsClientRoot}${api_path}`)
}

async function makeHandler<REQ, RSP>
Expand All @@ -33,7 +33,9 @@ async function sendApiReq<T>
if (ws.readyState === WebSocket.OPEN) {
const msg = reqStringify<T>(api_req)
ws.send(msg)
console.log(`send ${loggingHead} req:\n${msg}`)

if (build_meta.enableClientDevLog)
console.log(`send ${loggingHead} req:\n${msg}`)
} else
setTimeout(() => {
sendApiReq(loggingHead, ws, api_req)
Expand All @@ -47,10 +49,11 @@ async function recvApiRsp<T>
const msg = ev.data
const api_rsp = rspParse<T>(msg)
if (api_rsp.Seq === seq) {
ws
.removeEventListener("message", handler)
ws.removeEventListener("message", handler)
resolve(api_rsp)
console.log(`recv ${loggingHead} rsp:\n${msg}`)

if (build_meta.enableClientDevLog)
console.log(`recv ${loggingHead} rsp:\n${msg}`)
}
}
ws
Expand Down
4 changes: 0 additions & 4 deletions ws/meta.ts

This file was deleted.

15 changes: 9 additions & 6 deletions ws/server/helper.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import WebSocketSSR from "ws"
import {randomId, reqStringify, rspParse} from "@/ws/helper"
import {ApiRequest, ApiResponse} from "@/ws/helper"
import {wsServerRoot} from "~/ws/meta"
import build_meta from "~/field.meta"

export {
makeHandler
}

async function makeHandler<REQ, RSP>
(api_path: string, req: REQ) {
const conn = new WebSocketSSR(`${wsServerRoot}${api_path}`)
const conn = new WebSocketSSR(`${build_meta.wsServerRoot}${api_path}`)
const api_rsp = await request<REQ, RSP>(api_path, conn, req)
conn.close()
return api_rsp
Expand All @@ -28,7 +28,9 @@ async function sendApiReq<T>
if (ws.readyState === WebSocketSSR.OPEN) {
const msg = reqStringify<T>(api_req)
ws.send(msg)
console.log(`send ${loggingHead} req:\n${msg}`)

if (build_meta.enableServerDevLog)
console.log(`send ${loggingHead} req:\n${msg}`)
} else
setTimeout(() => {
sendApiReq(loggingHead, ws, api_req)
Expand All @@ -42,10 +44,11 @@ async function recvApiRsp<T>
const msg = data.toString()
const api_rsp = rspParse<T>(msg)
if (api_rsp.Seq === seq) {
ws
.off("message", handler)
ws.off("message", handler)
resolve(api_rsp)
console.log(`recv ${loggingHead} rsp:\n${msg}`)

if (build_meta.enableServerDevLog)
console.log(`recv ${loggingHead} rsp:\n${msg}`)
}
}
ws
Expand Down

0 comments on commit e9ac8c4

Please sign in to comment.