Skip to content

Commit

Permalink
Merge pull request #109 from terwer/dev
Browse files Browse the repository at this point in the history
feat: 支持设置自定义域名
  • Loading branch information
terwer committed Jun 21, 2023
2 parents fd738c2 + bf17949 commit fcc8bd9
Show file tree
Hide file tree
Showing 17 changed files with 75 additions and 22 deletions.
2 changes: 2 additions & 0 deletions app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type ThemeType = "system" | "dark" | "light"

interface AppConfig {
lang?: string
siteUrl?: string
siteTitle?: string
siteSlogan?: string
siteDescription?: string
Expand All @@ -44,6 +45,7 @@ interface AppConfig {

export default defineAppConfig<AppConfig>({
lang: "zh_CN",
siteUrl: "",
siteTitle: "浅海拾贝",
siteSlogan: "寻找未知的技术拼图",
siteDescription: "专注于Java后端开发及服务端、软件架构、微服务、自然语言处理等领域的技术分享。",
Expand Down
5 changes: 5 additions & 0 deletions components/default/setting/Basic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ useSeoMeta(seoMeta)
// datas
const formData = reactive({
siteUrl: setting.siteUrl,
homePageId: setting.homePageId,
themes: {
light: [
Expand Down Expand Up @@ -71,6 +72,7 @@ const formData = reactive({
// methods
const onSubmit = async () => {
try {
setting.siteUrl = formData.siteUrl
setting.homePageId = formData.homePageId
setting.theme ||= {}
setting.theme.lightTheme = formData.lightTheme
Expand All @@ -90,6 +92,9 @@ const onSubmit = async () => {
<template>
<div class="basic-setting">
<el-form label-width="85px">
<el-form-item :label="t('blog.site.url.label')">
<el-input v-model="formData.siteUrl" :placeholder="t('blog.site.url.placeholder')" />
</el-form-item>
<el-form-item :label="t('setting.basic.homePageId')">
<el-input v-model="formData.homePageId" />
</el-form-item>
Expand Down
2 changes: 1 addition & 1 deletion docker-compose-hub.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3'
services:
nuxt3-blog:
image: terwer/nuxt3-blog:1.3.0
image: terwer/nuxt3-blog:latest
ports:
- "3000:3000"
env_file:
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ services:
- ./.env.docker
restart: no
user: nuxt3-blog
image: terwer/nuxt3-blog:1.3.0
image: terwer/nuxt3-blog:latest
4 changes: 2 additions & 2 deletions docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pnpm nodeBuild
接着启动 node 服务器

```
node .output/server/index.mjs
NUXT_PUBLIC_DEFAULT_TYPE=siyuan node NUXT_PUBLIC_SIYUAN_API_URL=http://127.0.0.1:6806 node .output/server/index.mjs
```

然后打开
Expand All @@ -74,7 +74,7 @@ http://localhost:3000
```
pnpm nodeuild
docker compose up --build --remove-orphans
docker push terwer/nuxt3-blog:1.3.0
docker push terwer/nuxt3-blog:latest
```
最简单的使用

Expand Down
4 changes: 4 additions & 0 deletions locales/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export default {
"blog.share": "Share to web",
"blog.share.options": "Share options",
"blog.share.setting": "Share setting",
"blog.site.url.label": "Custom domain",
"blog.site.url": "Custom domain",
"blog.site.url.placeholder":
"Please fill in the complete address (if the port, you need to include the port), make sure that the domain name has been resolved, for example: http://siyuan.terwergreen.com:6808",
"blog.site.title.label": "Home title",
"blog.site.title": "Shallow sea shellfish",
"blog.site.slogan.label": "Home subtitle",
Expand Down
4 changes: 4 additions & 0 deletions locales/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export default {
"blog.share": "在线分享",
"blog.share.options": "分享选项",
"blog.share.setting": "分享设置",
"blog.site.url.label": "自定义域名",
"blog.site.url": "自定义域名",
"blog.site.url.placeholder":
"请填写完整地址(如有端口,需要包括端口),需确保域名已经解析,例如:http://siyuan.terwergreen.com:6808",
"blog.site.title.label": "主页标题",
"blog.site.title": "浅海拾贝",
"blog.site.slogan.label": "主页副标题",
Expand Down
33 changes: 26 additions & 7 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const generateDynamicV = () => {
}

const isDev = process.env.NODE_ENV === "development"
const appBase = "/"
const appBase = "/plugins/siyuan-blog/"
const staticV = generateDynamicV()

// https://nuxt.com/docs/api/configuration/nuxt-config
Expand All @@ -24,7 +24,14 @@ export default defineNuxtConfig({
},

// build modules
modules: ["@vueuse/nuxt", "@nuxtjs/i18n", "@element-plus/nuxt", "@nuxtjs/color-mode", "@pinia/nuxt", "@nuxt/image"],
modules: [
"@vueuse/nuxt",
"@nuxtjs/i18n-edge",
"@element-plus/nuxt",
"@nuxtjs/color-mode",
"@pinia/nuxt",
"@nuxt/image",
],

// vueuse
vueuse: {
Expand All @@ -47,7 +54,7 @@ export default defineNuxtConfig({
define: {
"process.env.DEV_MODE": `"${isDev}"`,
"process.env.APP_BASE": `"${appBase}"`,
"process.env.SSR": `"true"`,
"process.env.SSR": `"false"`,
},
plugins: [],
},
Expand All @@ -58,6 +65,14 @@ export default defineNuxtConfig({
themes: ["dark"],
},

// https://nuxt.com/docs/guide/going-further/custom-routing#hash-mode-spa
ssr: false,
router: {
options: {
hashMode: true,
},
},

css: ["~/assets/siyuan/style.styl", "~/assets/siyuan/index.styl"],

app: {
Expand Down Expand Up @@ -94,11 +109,15 @@ export default defineNuxtConfig({

// 环境变量
runtimeConfig: {
siyuanAuthToken: process.env.NUXT_SIYUAN_AUTH_TOKEN,
// siyuanAuthToken: process.env.NUXT_SIYUAN_AUTH_TOKEN,
siyuanAuthToken: "",
public: {
defaultType: process.env.NUXT_PUBLIC_DEFAULT_TYPE ?? "siyuan",
siyuanApiUrl: process.env.NUXT_PUBLIC_SIYUAN_API_URL ?? "http://127.0.0.1:6806",
waitTime: process.env.NUXT_PUBLIC_WAIT_TIME,
// defaultType: process.env.NUXT_PUBLIC_DEFAULT_TYPE,
defaultType: "siyuan",
// siyuanApiUrl: process.env.NUXT_PUBLIC_SIYUAN_API_URL,
siyuanApiUrl: "",
// waitTime: process.env.NUXT_PUBLIC_WAIT_TIME,
waitTime: "0",
},
},
})
7 changes: 4 additions & 3 deletions pages/share.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { useShareOptionToggle } from "~/composables/useShareOptionToggle"
import copy from "copy-to-clipboard"
import { useSiyuanApi } from "~/composables/api/useSiyuanApi"
import { PostStatusEnum } from "zhi-blog-api"
import { DateUtil, JsonUtil, StrUtil } from "zhi-common"
import { JsonUtil, StrUtil } from "zhi-common"
import { useMethodAsync } from "~/composables/useMethodAsync"
import { useMethod } from "~/composables/useMethod"
import { sendMessageToParent } from "~/utils/innerIframeEvent"
const logger = createAppLogger("share-page")
const { t } = useI18n()
Expand Down Expand Up @@ -43,7 +44,7 @@ useSeoMeta(seoMeta)
const attrs = JsonUtil.safeParse<any>(post?.attrs ?? "{}", {})
const formData = reactive({
shareEnabled: attrs["custom-publish-status"] === PostStatusEnum.PostStatusEnum_Publish,
shareLink: `${origin.value}${basePath}/s/${id.value}`,
shareLink: `${StrUtil.isEmptyString(setting?.siteUrl) ? origin.value : setting.siteUrl}${basePath}/s/${id.value}`,
optionEnabled: false,
expiredTime: attrs["custom-expires"] ?? "0",
isHome: setting.homePageId === id.value,
Expand All @@ -56,7 +57,7 @@ const { optionState, optionToggle } = useShareOptionToggle(formData.optionEnable
// }
const goHelp = async () => {
window.open("https://blog.terwer.space/docs")
window.open("https://blog.terwer.space/s/20230621001422-xsimx5v")
}
const copyWebLink = () => {
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/sh
#!/bin/bash

# 使用 Siyuan 构建配置
echo "Using Siyuan build config as SSE and SPA build."
Expand Down
2 changes: 1 addition & 1 deletion scripts/dev.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/sh
#!/bin/bash

# 使用 Siyuan 构建配置
echo "Using Siyuan build config as SSE and SPA build."
Expand Down
18 changes: 16 additions & 2 deletions scripts/docker.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
#!/usr/bin/sh
#!/bin/bash

# 使用 Docker 构建配置
echo "Using Docker build config as SSR build."

APP_VERSION=1.3.0

# 兼容 node 的构建
pnpm nodeBuild
docker compose up --build
docker compose up --build --remove-orphans

# 复制一份 terwer/nuxt3-blog:latest 镜像,并将它打上最新版本的标签
docker tag terwer/nuxt3-blog:latest terwer/nuxt3-blog:$APP_VERSION

# 登录 Docker Hub
# docker login

# 推送最新版本和 latest 标签
docker push terwer/nuxt3-blog:latest
docker push terwer/nuxt3-blog:$APP_VERSION
2 changes: 1 addition & 1 deletion scripts/node.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/sh
#!/bin/bash

# 使用 Node 构建配置
echo "Using Node build config as SSR build."
Expand Down
2 changes: 1 addition & 1 deletion scripts/serve.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/sh
#!/bin/bash

# 使用 Node 构建配置
echo "Using Node build config as SSR serve"
Expand Down
2 changes: 1 addition & 1 deletion scripts/vercel.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/sh
#!/bin/bash

# 使用 Vercel 构建配置
echo "Using Vercel build config as SSR build."
Expand Down
4 changes: 4 additions & 0 deletions siyuan/iframeEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export const registerIframeEvent = (pluginInstance: SiyuanBlog) => {
// 监听 message 事件
window.addEventListener("message", (event) => {
const iframe = document.getElementById(popContentIframeId) as HTMLIFrameElement
if (!iframe) {
logger.debug(`popContent not show, ignore`)
return
}

// 判断是否是来自指定 iframe 的消息
if (event.source === iframe.contentWindow) {
Expand Down
2 changes: 1 addition & 1 deletion utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const isUseSiyuanApi = () => {
const env = useRuntimeConfig()
// docker - 在 .env.docker 配置 NUXT_PUBLIC_DEFAULT_TYPE=siyuan
// vercel - 在环境变量配置 NUXT_PUBLIC_DEFAULT_TYPE=siyuan
// node - 启动参数加 NUXT_PUBLIC_DEFAULT_TYPE=siyuan node NUXT_PUBLIC_SIYUAN_API_URL=http://127.0.0.1:6806 .output/server.,js
// node - 启动参数加 NUXT_PUBLIC_DEFAULT_TYPE=siyuan node NUXT_PUBLIC_SIYUAN_API_URL=http://127.0.0.1:6806
// 插件SPA(PC客户端) - nuxt.siyuan.config.ts 写死 NUXT_PUBLIC_DEFAULT_TYPE: siyuan
// 插件SPA(Docker浏览器客户端)- nuxt.siyuan.config.ts 写死 NUXT_PUBLIC_DEFAULT_TYPE: siyuan
// 插件SPA(本地客户端浏览器)- nuxt.siyuan.config.ts 写死 NUXT_PUBLIC_DEFAULT_TYPE: siyuan
Expand Down

1 comment on commit fcc8bd9

@vercel
Copy link

@vercel vercel bot commented on fcc8bd9 Jun 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.