diff --git a/components/default/HeaderMenu.vue b/components/default/HeaderMenu.vue
index dcb41ae..8b2d791 100644
--- a/components/default/HeaderMenu.vue
+++ b/components/default/HeaderMenu.vue
@@ -36,14 +36,33 @@
+
+
+
+
+
+ {{ $t('header.search') }}
+
+
+
@@ -107,4 +98,12 @@ export default {
font-size: 32px;
color: var(--el-color-primary);
}
+
+#tagArea {
+ margin-top: 10px;
+}
+
+#tagArea .post-tag {
+ margin-right: 10px;
+}
\ No newline at end of file
diff --git a/pages/s/[keyword].vue b/pages/s/[keyword].vue
new file mode 100644
index 0000000..0f63900
--- /dev/null
+++ b/pages/s/[keyword].vue
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/plugins/hljs/vue-hljs/main.js b/plugins/hljs/vue-hljs/main.js
index fd0cadf..c1ed013 100644
--- a/plugins/hljs/vue-hljs/main.js
+++ b/plugins/hljs/vue-hljs/main.js
@@ -5,6 +5,7 @@ import "./vs.css";
import {renderHTML} from "~/lib/markdownUtil";
import {unescapeHTML} from "~/lib/strUtil";
import logUtil from "~/lib/logUtil";
+import {prettyHtml} from "~/lib/htmlUtil";
const vueHljs = {};
@@ -15,7 +16,8 @@ vueHljs.install = Vue => {
);
Vue.directive("highlight", el => {
- const html = renderHTML(el.innerHTML)
+ let html = renderHTML(el.innerHTML)
+ html = prettyHtml(html)
// console.log(html)
el.innerHTML = html;
diff --git a/server/api/endpoint/getPost.ts b/server/api/endpoint/getPost.ts
index 18a6ca7..9133d07 100644
--- a/server/api/endpoint/getPost.ts
+++ b/server/api/endpoint/getPost.ts
@@ -2,21 +2,23 @@ import {API_TYPE_CONSTANTS} from "~/lib/constants";
import {API} from "~/lib/api";
export default defineEventHandler(async (event) => {
+ const env = useRuntimeConfig()
+ console.log('Runtime env:', env)
+
const query = useQuery(event)
if (query.t instanceof Array) {
throw new Error("参数类型错误")
}
- const type = query.t || API_TYPE_CONSTANTS.API_TYPE_WORDPRESS
+
+ const defaultType = env.DEFAULT_TYPE || API_TYPE_CONSTANTS.API_TYPE_WORDPRESS
+ const type = query.t || defaultType
if (query.postid instanceof Array) {
throw new Error("参数类型错误")
}
const postid = query.postid || "1"
- const env = useRuntimeConfig()
- console.log('Runtime env:', env)
-
const api = new API(type, env)
const result = await api.getPost(postid)
diff --git a/server/api/endpoint/getRecentPosts.ts b/server/api/endpoint/getRecentPosts.ts
index bbc686f..1af7127 100644
--- a/server/api/endpoint/getRecentPosts.ts
+++ b/server/api/endpoint/getRecentPosts.ts
@@ -3,23 +3,34 @@ import {API} from "~/lib/api";
import logUtil from "~/lib/logUtil";
export default defineEventHandler(async (event) => {
+ const env = useRuntimeConfig()
+ logUtil.logInfo('Runtime env:', env)
+
const query = useQuery(event)
if (query.t instanceof Array) {
throw new Error("参数类型错误")
}
logUtil.logInfo("query.t", query.t)
- const type = query.t || API_TYPE_CONSTANTS.API_TYPE_WORDPRESS
+ if (query.pg instanceof Array) {
+ throw new Error("参数类型错误")
+ }
+
+ const defaultType = env.DEFAULT_TYPE || API_TYPE_CONSTANTS.API_TYPE_WORDPRESS
+ const type = query.t || defaultType
const num = 10
- const page = 1
- const keyword = ""
+ const page = query.pg || "1"
- const env = useRuntimeConfig()
- logUtil.logInfo('Runtime env:', env)
+ if (query.k instanceof Array) {
+ throw new Error("参数类型错误")
+ }
+
+ const keyword = query.k || ""
const api = new API(type, env)
- const result = await api.getRecentPosts(num, page, keyword)
+ // logUtil.logInfo("keyword=>", keyword)
+ const result = await api.getRecentPosts(num, parseInt(page) - 1, keyword)
return {
code: 0,
diff --git a/stores/searchStore.ts b/stores/searchStore.ts
new file mode 100644
index 0000000..f06d9bf
--- /dev/null
+++ b/stores/searchStore.ts
@@ -0,0 +1,14 @@
+import {defineStore} from "pinia";
+
+/**
+ * 搜索关键字存储
+ */
+export const useSearchStore = defineStore("sk", () => {
+ const sk = ref("")
+
+ function setSk(s: string) {
+ sk.value = s
+ }
+
+ return {sk, setSk}
+})
\ No newline at end of file