Skip to content

Commit

Permalink
feat: Add static blog
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Apr 7, 2023
1 parent 72506fa commit 4624911
Show file tree
Hide file tree
Showing 41 changed files with 1,058 additions and 133 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ to:
- Blog plugin
- It can handle both the theme and the preview. Installing the zhi theme is equivalent to installing an additional
plugin system and an online blog.
- Blog homepage: http://127.0.0.1:6806/appearance/themes/zhi/blog/
- Widget version of the blog management and publishing
- SPA blog homepage: http://127.0.0.1:6806/appearance/themes/zhi/web/blog/ <sup>simple</sup>
- SSR blog homepage: http://127.0.0.1:6806/appearance/themes/zhi/server/blog/ <sup>seo friendly</sup>
- Widget version of the blog management and publishing [Deprecated]
homepage: http://127.0.0.1:6806/widgets/sy-post-publisher/blog/?from=siyuanNewWin

> Note: 🌹 The plugin system is provided by enthusiastic community developers. Please understand the relevant mechanisms in
Expand Down
12 changes: 9 additions & 3 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,17 @@
- 文档图片背景自动透明插件
- 博客插件

- 同时搞定主题与预览,安装了 zhi 主题相当于额外安装了一个插件系统,一个在线博客
- 同时搞定主题与预览,安装了 zhi 主题相当于额外安装了一个插件系统,两个在线博客

博客主页:http://127.0.0.1:6806/appearance/themes/zhi/blog/
静态博客主页:http://127.0.0.1:6806/appearance/themes/zhi/web/blog/ <sup>简单</sup>
动态博客主页:http://127.0.0.1:3000/appearance/themes/zhi/server/blog/ <sup>SEO友好</sup>

挂件版博客管理与发布主页:http://127.0.0.1:6806/widgets/sy-post-publisher/blog/?from=siyuanNewWin
特别说明:
1. 博客服务已经自带,开箱即用,无需任何配置。
2. 静态博客如果想自部署,可拷贝 `web/blog` 目录 ,然后用 `Nginx` 伺服即可,无需其他。
3. 动态博客如果想自部署,可拷贝 `server/blog` 目录 ,然后用 `Node` 环境启动,也可自行通过 `docker` 镜像或者下面的 `docker-compose.yml` 启动,也可源码编译,然后部署到 `Vercel`

挂件版博客管理与发布主页:http://127.0.0.1:6806/widgets/sy-post-publisher/blog/?from=siyuanNewWin [功能重叠][已废弃][建议使用新版博客]

> 注意事项:🌹 插件系统为社区热心开发者提供,请详细了解相关机制之后再使用。
Expand Down
2 changes: 1 addition & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"default",
"!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
"!{projectRoot}/tsconfig.spec.json",
"!{projectRoot}/.eslintrc.json",
"!{projectRoot}/.eslintrc.json"
],
"sharedGlobals": ["{workspaceRoot}/babel.config.json"]
},
Expand Down
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "GPL",
"scripts": {
"build": "nx run-many --target=build --exclude=zhi-docs",
"zhi-build": "nx run-many --target=zhi-build --exclude=zhi-docs",
"zhi-build": "nx zhi-build zhi-core",
"test": "nx run-many --target=test --exclude=zhi-docs",
"lint": "nx run-many --target=lint --exclude=zhi-docs",
"serve": "nx serve <project>",
Expand Down Expand Up @@ -34,6 +34,8 @@
"@nrwl/webpack": "15.9.2",
"@nrwl/workspace": "15.9.2",
"@nx-plus/docusaurus": "15.0.0-rc.0",
"@nx-plus/nuxt": "^14.1.0",
"@nxext/vue": "15.7.0-Beta.3",
"@nxlv/python": "^15.7.0",
"@nxtensions/astro": "3.5.0",
"@rollup/plugin-node-resolve": "^15.0.2",
Expand All @@ -48,8 +50,12 @@
"@types/xml2js": "^0.4.11",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.57.0",
"@vitejs/plugin-vue": "^4.0.0",
"@vitest/coverage-c8": "~0.29.8",
"@vitest/ui": "^0.25.8",
"@vue/eslint-config-prettier": "^7.0.0",
"@vue/eslint-config-typescript": "^11.0.2",
"@vue/test-utils": "^2.2.6",
"@vuepress/client": "2.0.0-beta.61",
"@vuepress/plugin-register-components": "^2.0.0-beta.61",
"@vuepress/utils": "2.0.0-beta.61",
Expand Down Expand Up @@ -119,6 +125,7 @@
"regenerator-runtime": "0.13.7",
"siyuan": "^0.3.18",
"tslib": "^2.5.0",
"vue-tsc": "^1.0.24",
"xml2js": "^0.4.23"
}
}
3 changes: 1 addition & 2 deletions packages/zhi-core/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
"dependsOn": []
},
"zhi-build": {
"dependsOn": ["build"],
"command": "cp -r dist/packages/zhi/* /Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/ && cd /Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/ && npm i --registry=https://registry.npmmirror.com && echo 'zhi-core dist copy success'"
"command": "bash packages/zhi-core/script/zhi-build.sh"
}
},
"tags": []
Expand Down
5 changes: 5 additions & 0 deletions packages/zhi-core/script/zhi-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
ZHI_THEME_DIR=/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi

cp -r dist/packages/zhi/* $ZHI_THEME_DIR/
echo "zhi dist copy success"
14 changes: 7 additions & 7 deletions packages/zhi-core/src/lib/core/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

import DependencyItem from "../models/DependencyItem"
import PluginSystem from "./plugin-system"
import HttpService from "../modules/http-service"
import BlogEntry from "../modules/blog"
import WebBlogEntry from "../web-modules/blog"

/**
* zhi主题统一生命周期管理
Expand All @@ -36,15 +36,15 @@ import BlogEntry from "../modules/blog"
*/
class Lifecycle {
private pluginSystem
private httpService
private blogEntry
private webBlogEntry

private _dynamicImports = <DependencyItem[]>[]

constructor() {
this.pluginSystem = new PluginSystem()
this.httpService = new HttpService()
this.blogEntry = new BlogEntry()
this.webBlogEntry = new WebBlogEntry()
}

get dynamicImports(): DependencyItem[] {
Expand Down Expand Up @@ -91,13 +91,13 @@ class Lifecycle {
// const fontAwesomeImports = fontAwesome.initFontAwesome()
// vendorImports = vendorImports.concat(fontAwesomeImports)

// express 服务
const httpServiceImports = await this.httpService.initHttpService()
vendorImports = vendorImports.concat(httpServiceImports)

// blog
const blogImports = await this.blogEntry.initBlog()
vendorImports = vendorImports.concat(blogImports)

// webBlog
const webBlogImports = await this.webBlogEntry.initWebBlog()
vendorImports = vendorImports.concat(webBlogImports)
return vendorImports
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,25 @@
*/

import DependencyItem from "../../models/DependencyItem"
import { DeviceType } from "zhi-common"
import ZhiUtil from "../../core/util/ZhiUtil"

/**
* 主题的 HTTP 服务
*/
class HttpService {
class WebBlogEntry {
private readonly common

constructor() {
this.common = ZhiUtil.zhiCommon()
}

/**
* 初始化 HTTP 服务
* 初始化 blog 入口
*/
async initHttpService(): Promise<DependencyItem[]> {
async initWebBlog(): Promise<DependencyItem[]> {
return [
// // blogMiddlewareDepItem
// {
// format: "cjs",
// libpath: this.common.siyuanUtil.joinPath("modules", "blog-middleware", "index.js"),
// importType: "require",
// runAs: DeviceType.DeviceType_Siyuan_MainWin,
// },
// // blogMiddlewareWebDepItem
// {
// format: "cjs",
// libpath: this.common.siyuanUtil.joinPath("web-modules", "blog-middleware", "index.mjs"),
// importType: "import",
// runAs: DeviceType.DeviceType_Chrome_Browser,
// },
// blogDepItem
// Web博客采用Vue+SPA方案,无需后端支持,但是SEO不好,建议不考虑SEO的情况下用
// 这里还是留个口子,如果后面需要加载后端可以在这里写
]
}
}

export default HttpService
export default WebBlogEntry
10 changes: 10 additions & 0 deletions packages/zhi-web-modules-blog-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": ["plugin:cypress/recommended", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
}
]
}
8 changes: 8 additions & 0 deletions packages/zhi-web-modules-blog-e2e/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from "cypress"
import { nxE2EPreset } from "@nrwl/cypress/plugins/cypress-preset"

export default defineConfig({
e2e: nxE2EPreset(__dirname, {
bundler: "vite",
}),
})
30 changes: 30 additions & 0 deletions packages/zhi-web-modules-blog-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "zhi-web-modules-blog-e2e",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/zhi-web-modules-blog-e2e/src",
"projectType": "application",
"targets": {
"e2e": {
"executor": "@nrwl/cypress:cypress",
"options": {
"cypressConfig": "packages/zhi-web-modules-blog-e2e/cypress.config.ts",
"devServerTarget": "zhi-web-modules-blog:serve:development",
"testingType": "e2e"
},
"configurations": {
"production": {
"devServerTarget": "zhi-web-modules-blog:serve:production"
}
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["packages/zhi-web-modules-blog-e2e/**/*.{js,ts}"]
}
}
},
"tags": [],
"implicitDependencies": ["zhi-web-modules-blog"]
}
13 changes: 13 additions & 0 deletions packages/zhi-web-modules-blog-e2e/src/e2e/app.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { getGreeting } from "../support/app.po"

describe("zhi-web-modules-blog", () => {
beforeEach(() => cy.visit("/"))

it("should display welcome message", () => {
// Custom command example, see `../support/commands.ts` file
cy.login("my-email@something.com", "myPassword")

// Function helper example, see `../support/app.po.ts` file
getGreeting().contains("Welcome zhi-web-modules-blog")
})
})
4 changes: 4 additions & 0 deletions packages/zhi-web-modules-blog-e2e/src/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io"
}
1 change: 1 addition & 0 deletions packages/zhi-web-modules-blog-e2e/src/support/app.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const getGreeting = () => cy.get("h1")
33 changes: 33 additions & 0 deletions packages/zhi-web-modules-blog-e2e/src/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************

// eslint-disable-next-line @typescript-eslint/no-namespace
declare namespace Cypress {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Chainable<Subject> {
login(email: string, password: string): void
}
}
//
// -- This is a parent command --
Cypress.Commands.add("login", (email, password) => {
console.log("Custom command example: Login", email, password)
})
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
17 changes: 17 additions & 0 deletions packages/zhi-web-modules-blog-e2e/src/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import "./commands"
10 changes: 10 additions & 0 deletions packages/zhi-web-modules-blog-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"sourceMap": false,
"outDir": "../../dist/out-tsc",
"allowJs": true,
"types": ["cypress", "node"]
},
"include": ["src/**/*.ts", "src/**/*.js", "cypress.config.ts"]
}
24 changes: 24 additions & 0 deletions packages/zhi-web-modules-blog/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": [
"plugin:vue/vue3-essential",
"eslint:recommended",
"@vue/eslint-config-typescript",
"@vue/eslint-config-prettier",
"../../.eslintrc.json"
],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
13 changes: 13 additions & 0 deletions packages/zhi-web-modules-blog/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
Loading

0 comments on commit 4624911

Please sign in to comment.