Skip to content

Commit 509a194

Browse files
committed
feat:#1 集成Nuxt3测试
1 parent 7947072 commit 509a194

24 files changed

+787
-56
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.vercel
33
.nuxt
44
node_modules
5+
.env

app.vue

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div>
3-
<NuxtWelcome />
4-
</div>
5-
</template>
2+
<NuxtLayout>
3+
<NuxtPage/>
4+
</NuxtLayout>
5+
</template>

layouts/custom.vue

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<template>
2+
<div>
3+
Some *custom* layout
4+
<slot/>
5+
</div>
6+
</template>

layouts/default.vue

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<template>
2+
<div>
3+
A *default* layout
4+
<slot/>
5+
</div>
6+
</template>

lib/api.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
import {SiYuanApiAdaptor} from "~/lib/siyuan/siYuanApiAdaptor";
1+
import {SiYuanApiAdaptor} from "~/lib/platform/siyuan/siYuanApiAdaptor";
22
import {API_TYPE_CONSTANTS} from "~/lib/constants";
33
import {Post} from "~/lib/common/post";
44
import {UserBlog} from "~/lib/common/userBlog";
5+
import {JvueApiAdaptor} from "~/lib/platform/metaweblog/jvue/jvueApiAdaptor";
6+
import {ConfApiAdaptor} from "~/lib/platform/metaweblog/conf/confApiAdaptor";
7+
import {CnblogsApiAdaptor} from "~/lib/platform/metaweblog/cnblogs/cnblogsApiAdaptor";
58

9+
/**
10+
* 通用API定义
11+
*/
612
export interface IApi {
713
/**
814
* 博客配置列表
@@ -35,6 +41,15 @@ export class API implements IApi {
3541
case API_TYPE_CONSTANTS.API_TYPE_SIYUAN:
3642
this.apiAdaptor = new SiYuanApiAdaptor(env)
3743
break;
44+
case API_TYPE_CONSTANTS.API_TYPE_JVUE:
45+
this.apiAdaptor = new JvueApiAdaptor(env)
46+
break;
47+
case API_TYPE_CONSTANTS.API_TYPE_CONF:
48+
this.apiAdaptor = new ConfApiAdaptor(env)
49+
break;
50+
case API_TYPE_CONSTANTS.API_TYPE_CNBLOGS:
51+
this.apiAdaptor = new CnblogsApiAdaptor(env)
52+
break;
3853
default:
3954
throw new Error("未找到接口适配器,请检查参数")
4055
}

lib/constants.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,25 @@
22
* 思源笔记
33
*/
44
const API_TYPE_SIYUAN = "siyuan"
5+
/**
6+
* JVue
7+
*/
8+
const API_TYPE_JVUE = "jvue"
9+
/**
10+
* Confluence
11+
*/
12+
const API_TYPE_CONF = "conf"
13+
/**
14+
* Cnblogs
15+
*/
16+
const API_TYPE_CNBLOGS = "cnblogs"
517

618
/**
719
* API类型常量定义
820
*/
921
export const API_TYPE_CONSTANTS = {
10-
API_TYPE_SIYUAN
22+
API_TYPE_SIYUAN,
23+
API_TYPE_JVUE,
24+
API_TYPE_CONF,
25+
API_TYPE_CNBLOGS
1126
}

lib/htmlUtil.ts

+34-36
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
// const showdown = require("showdown")
2-
// const converter = new showdown.Converter();
3-
//
4-
// /**
5-
// * 将Markdown转换为HTML
6-
// * @param md Markdown
7-
// * @returns {*} HTML
8-
// */
9-
// export function mdToHtml(md: string) {
10-
// let html = converter.makeHtml(md);
11-
// return removeWidgetTag(html);
12-
// }
13-
// instdead by lute
14-
151
import {renderHTML} from "./markdownUtil";
162

173
/**
@@ -33,7 +19,7 @@ export function removeTitleNumber(str: string) {
3319
* @param str 原字符
3420
* @returns {*|string} 删除后的字符
3521
*/
36-
export function removeWidgetTag(str: string) {
22+
function removeWidgetTag(str: string) {
3723
let newstr = str
3824

3925
// 旧版发布挂件
@@ -54,24 +40,6 @@ export function removeWidgetTag(str: string) {
5440
return newstr
5541
}
5642

57-
/**
58-
* 截取指定长度html
59-
* @param html html
60-
* @param length 长度
61-
* @param ignore 不要结尾省略号
62-
* @returns {string} 结果
63-
*/
64-
export function parseHtml(html: string, length: number, ignore?: boolean) {
65-
let allText = filterHtml(html);
66-
if (allText.length < length) {
67-
return allText;
68-
}
69-
if (ignore) {
70-
return allText.substring(0, length);
71-
}
72-
return allText.substring(0, length) + "...";
73-
}
74-
7543
/**
7644
* 去除html标签,残缺不全也可以
7745
* @param str
@@ -115,13 +83,43 @@ function filterHtml(str: string) {
11583
return str;
11684
}
11785

86+
/**
87+
* 去除挂件占位符HTML、标题序号等
88+
* @param html 原始HTML
89+
*/
90+
export function prettyHtml(html: string) {
91+
let newHtml = html
92+
newHtml = removeWidgetTag(newHtml)
93+
newHtml = removeTitleNumber(newHtml)
94+
return newHtml
95+
}
96+
97+
/**
98+
* 截取指定长度字符
99+
* @param text
100+
* @param length 长度
101+
* @param ignore 不要结尾省略号
102+
* @returns {string} 结果
103+
*/
104+
export function subText(text: string, length: number, ignore?: boolean) {
105+
let allText = text
106+
if (allText.length < length) {
107+
return allText;
108+
}
109+
if (ignore) {
110+
return allText.substring(0, length);
111+
}
112+
return allText.substring(0, length) + "...";
113+
}
114+
118115
/**
119116
* 将Markdown转换为纯文本
120117
* @param md
121118
* @returns {string}
122119
*/
123-
export function mdToPlanText(md: string) {
120+
export function mdToPlainText(md: string) {
124121
let html = renderHTML(md)
125-
html = removeWidgetTag(html)
126-
return filterHtml(html)
122+
html = prettyHtml(html)
123+
html = filterHtml(html)
124+
return html
127125
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {MetaWeblogApiAdaptor} from "~/lib/platform/metaweblog/metaweblogApiAdaptor";
2+
import {IApi} from "~/lib/api";
3+
import {API_TYPE_CONSTANTS} from "~/lib/constants";
4+
import {MetaWeblogApi} from "~/lib/platform/metaweblog/metaweblogApi";
5+
6+
/**
7+
* 博客园的API适配器
8+
*/
9+
export class CnblogsApiAdaptor extends MetaWeblogApiAdaptor implements IApi {
10+
private readonly env:any
11+
12+
constructor(env:any) {
13+
super();
14+
15+
this.env = env
16+
this.apiUrl = process.env.CNBLOGS_API_URL || ""
17+
this.username = process.env.CNBLOGS_USERNAME || ""
18+
this.password = process.env.CNBLOGS_PASSWORD || ""
19+
this.appkey = API_TYPE_CONSTANTS.API_TYPE_CNBLOGS
20+
21+
this.metaWeblog = new MetaWeblogApi(this.appkey, this.apiUrl, this.username, this.password);
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {IApi} from "~/lib/api";
2+
import {MetaWeblogApiAdaptor} from "~/lib/platform/metaweblog/metaweblogApiAdaptor";
3+
import {API_TYPE_CONSTANTS} from "~/lib/constants";
4+
import {MetaWeblogApi} from "~/lib/platform/metaweblog/metaweblogApi";
5+
6+
/**
7+
* Confluence的API适配器
8+
*/
9+
export class ConfApiAdaptor extends MetaWeblogApiAdaptor implements IApi {
10+
private readonly env: any
11+
12+
constructor(env: any) {
13+
super();
14+
15+
this.env = env
16+
this.apiUrl = env.CONF_API_URL || ""
17+
this.username = env.CONF_USERNAME || ""
18+
this.password = env.CONF_PASSWORD || ""
19+
this.appkey = API_TYPE_CONSTANTS.API_TYPE_CONF
20+
21+
this.metaWeblog = new MetaWeblogApi(this.appkey, this.apiUrl, this.username, this.password);
22+
}
23+
}
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import logUtil from "~/lib/logUtil";
2+
// @ts-ignore
3+
import * as Serializer from 'xmlrpc/lib/serializer'
4+
import { parse } from 'arraybuffer-xml-parser';
5+
console.log(Serializer)
6+
7+
/**
8+
* 自定义xmlrpc的请求与解析,解决apache xmlrpc的扩展问题
9+
* @param apiUrl
10+
* @param reqMethod
11+
* @param reqParams
12+
*/
13+
export async function fetchCustom(apiUrl: string, reqMethod: string, reqParams: Array<string>) {
14+
try {
15+
const methodBodyXml = Serializer.serializeMethodCall(reqMethod, reqParams, "utf8")
16+
17+
const response = await fetch(apiUrl, {
18+
method: "POST",
19+
headers: {
20+
"content-type": "text/xml"
21+
},
22+
body: methodBodyXml
23+
})
24+
const resXml = await response.text()
25+
logUtil.logInfo("resXml=>", resXml)
26+
27+
const parseResult: any = parse(resXml)
28+
logUtil.logInfo("parseResult=>", parseResult)
29+
30+
const resJson = parseResult.methodResponse || {}
31+
logUtil.logInfo("resJson=>", JSON.stringify(resJson))
32+
33+
return resJson
34+
} catch (e: any) {
35+
throw new Error(e)
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {MetaWeblogApiAdaptor} from "~/lib/platform/metaweblog/metaweblogApiAdaptor";
2+
import {API_TYPE_CONSTANTS} from "~/lib/constants";
3+
import {MetaWeblogApi} from "~/lib/platform/metaweblog/metaweblogApi";
4+
import {IApi} from "~/lib/api";
5+
6+
/**
7+
* JVue的API适配器
8+
*/
9+
export class JvueApiAdaptor extends MetaWeblogApiAdaptor implements IApi {
10+
private readonly env:any
11+
12+
constructor(env:any) {
13+
super();
14+
15+
this.env = env
16+
this.apiUrl = env.JVUE_API_URL || ""
17+
this.username = env.JVUE_USERNAME || ""
18+
this.password = env.JVUE_PASSWORD || ""
19+
this.appkey = API_TYPE_CONSTANTS.API_TYPE_JVUE
20+
21+
this.metaWeblog = new MetaWeblogApi(this.appkey, this.apiUrl, this.username, this.password);
22+
}
23+
}

0 commit comments

Comments
 (0)