Skip to content

Commit

Permalink
feat:#1 集成Nuxt3测试
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Aug 29, 2022
1 parent 7947072 commit 509a194
Show file tree
Hide file tree
Showing 24 changed files with 787 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.vercel
.nuxt
node_modules
.env
8 changes: 4 additions & 4 deletions app.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div>
<NuxtWelcome />
</div>
</template>
<NuxtLayout>
<NuxtPage/>
</NuxtLayout>
</template>
6 changes: 6 additions & 0 deletions layouts/custom.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<template>
<div>
Some *custom* layout
<slot/>
</div>
</template>
6 changes: 6 additions & 0 deletions layouts/default.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<template>
<div>
A *default* layout
<slot/>
</div>
</template>
17 changes: 16 additions & 1 deletion lib/api.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import {SiYuanApiAdaptor} from "~/lib/siyuan/siYuanApiAdaptor";
import {SiYuanApiAdaptor} from "~/lib/platform/siyuan/siYuanApiAdaptor";
import {API_TYPE_CONSTANTS} from "~/lib/constants";
import {Post} from "~/lib/common/post";
import {UserBlog} from "~/lib/common/userBlog";
import {JvueApiAdaptor} from "~/lib/platform/metaweblog/jvue/jvueApiAdaptor";
import {ConfApiAdaptor} from "~/lib/platform/metaweblog/conf/confApiAdaptor";
import {CnblogsApiAdaptor} from "~/lib/platform/metaweblog/cnblogs/cnblogsApiAdaptor";

/**
* 通用API定义
*/
export interface IApi {
/**
* 博客配置列表
Expand Down Expand Up @@ -35,6 +41,15 @@ export class API implements IApi {
case API_TYPE_CONSTANTS.API_TYPE_SIYUAN:
this.apiAdaptor = new SiYuanApiAdaptor(env)
break;
case API_TYPE_CONSTANTS.API_TYPE_JVUE:
this.apiAdaptor = new JvueApiAdaptor(env)
break;
case API_TYPE_CONSTANTS.API_TYPE_CONF:
this.apiAdaptor = new ConfApiAdaptor(env)
break;
case API_TYPE_CONSTANTS.API_TYPE_CNBLOGS:
this.apiAdaptor = new CnblogsApiAdaptor(env)
break;
default:
throw new Error("未找到接口适配器,请检查参数")
}
Expand Down
17 changes: 16 additions & 1 deletion lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,25 @@
* 思源笔记
*/
const API_TYPE_SIYUAN = "siyuan"
/**
* JVue
*/
const API_TYPE_JVUE = "jvue"
/**
* Confluence
*/
const API_TYPE_CONF = "conf"
/**
* Cnblogs
*/
const API_TYPE_CNBLOGS = "cnblogs"

/**
* API类型常量定义
*/
export const API_TYPE_CONSTANTS = {
API_TYPE_SIYUAN
API_TYPE_SIYUAN,
API_TYPE_JVUE,
API_TYPE_CONF,
API_TYPE_CNBLOGS
}
70 changes: 34 additions & 36 deletions lib/htmlUtil.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
// const showdown = require("showdown")
// const converter = new showdown.Converter();
//
// /**
// * 将Markdown转换为HTML
// * @param md Markdown
// * @returns {*} HTML
// */
// export function mdToHtml(md: string) {
// let html = converter.makeHtml(md);
// return removeWidgetTag(html);
// }
// instdead by lute

import {renderHTML} from "./markdownUtil";

/**
Expand All @@ -33,7 +19,7 @@ export function removeTitleNumber(str: string) {
* @param str 原字符
* @returns {*|string} 删除后的字符
*/
export function removeWidgetTag(str: string) {
function removeWidgetTag(str: string) {
let newstr = str

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

/**
* 截取指定长度html
* @param html html
* @param length 长度
* @param ignore 不要结尾省略号
* @returns {string} 结果
*/
export function parseHtml(html: string, length: number, ignore?: boolean) {
let allText = filterHtml(html);
if (allText.length < length) {
return allText;
}
if (ignore) {
return allText.substring(0, length);
}
return allText.substring(0, length) + "...";
}

/**
* 去除html标签,残缺不全也可以
* @param str
Expand Down Expand Up @@ -115,13 +83,43 @@ function filterHtml(str: string) {
return str;
}

/**
* 去除挂件占位符HTML、标题序号等
* @param html 原始HTML
*/
export function prettyHtml(html: string) {
let newHtml = html
newHtml = removeWidgetTag(newHtml)
newHtml = removeTitleNumber(newHtml)
return newHtml
}

/**
* 截取指定长度字符
* @param text
* @param length 长度
* @param ignore 不要结尾省略号
* @returns {string} 结果
*/
export function subText(text: string, length: number, ignore?: boolean) {
let allText = text
if (allText.length < length) {
return allText;
}
if (ignore) {
return allText.substring(0, length);
}
return allText.substring(0, length) + "...";
}

/**
* 将Markdown转换为纯文本
* @param md
* @returns {string}
*/
export function mdToPlanText(md: string) {
export function mdToPlainText(md: string) {
let html = renderHTML(md)
html = removeWidgetTag(html)
return filterHtml(html)
html = prettyHtml(html)
html = filterHtml(html)
return html
}
23 changes: 23 additions & 0 deletions lib/platform/metaweblog/cnblogs/cnblogsApiAdaptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {MetaWeblogApiAdaptor} from "~/lib/platform/metaweblog/metaweblogApiAdaptor";
import {IApi} from "~/lib/api";
import {API_TYPE_CONSTANTS} from "~/lib/constants";
import {MetaWeblogApi} from "~/lib/platform/metaweblog/metaweblogApi";

/**
* 博客园的API适配器
*/
export class CnblogsApiAdaptor extends MetaWeblogApiAdaptor implements IApi {
private readonly env:any

constructor(env:any) {
super();

this.env = env
this.apiUrl = process.env.CNBLOGS_API_URL || ""
this.username = process.env.CNBLOGS_USERNAME || ""
this.password = process.env.CNBLOGS_PASSWORD || ""
this.appkey = API_TYPE_CONSTANTS.API_TYPE_CNBLOGS

this.metaWeblog = new MetaWeblogApi(this.appkey, this.apiUrl, this.username, this.password);
}
}
23 changes: 23 additions & 0 deletions lib/platform/metaweblog/conf/confApiAdaptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {IApi} from "~/lib/api";
import {MetaWeblogApiAdaptor} from "~/lib/platform/metaweblog/metaweblogApiAdaptor";
import {API_TYPE_CONSTANTS} from "~/lib/constants";
import {MetaWeblogApi} from "~/lib/platform/metaweblog/metaweblogApi";

/**
* Confluence的API适配器
*/
export class ConfApiAdaptor extends MetaWeblogApiAdaptor implements IApi {
private readonly env: any

constructor(env: any) {
super();

this.env = env
this.apiUrl = env.CONF_API_URL || ""
this.username = env.CONF_USERNAME || ""
this.password = env.CONF_PASSWORD || ""
this.appkey = API_TYPE_CONSTANTS.API_TYPE_CONF

this.metaWeblog = new MetaWeblogApi(this.appkey, this.apiUrl, this.username, this.password);
}
}
37 changes: 37 additions & 0 deletions lib/platform/metaweblog/customXmlrpc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import logUtil from "~/lib/logUtil";
// @ts-ignore
import * as Serializer from 'xmlrpc/lib/serializer'
import { parse } from 'arraybuffer-xml-parser';
console.log(Serializer)

/**
* 自定义xmlrpc的请求与解析,解决apache xmlrpc的扩展问题
* @param apiUrl
* @param reqMethod
* @param reqParams
*/
export async function fetchCustom(apiUrl: string, reqMethod: string, reqParams: Array<string>) {
try {
const methodBodyXml = Serializer.serializeMethodCall(reqMethod, reqParams, "utf8")

const response = await fetch(apiUrl, {
method: "POST",
headers: {
"content-type": "text/xml"
},
body: methodBodyXml
})
const resXml = await response.text()
logUtil.logInfo("resXml=>", resXml)

const parseResult: any = parse(resXml)
logUtil.logInfo("parseResult=>", parseResult)

const resJson = parseResult.methodResponse || {}
logUtil.logInfo("resJson=>", JSON.stringify(resJson))

return resJson
} catch (e: any) {
throw new Error(e)
}
}
23 changes: 23 additions & 0 deletions lib/platform/metaweblog/jvue/jvueApiAdaptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {MetaWeblogApiAdaptor} from "~/lib/platform/metaweblog/metaweblogApiAdaptor";
import {API_TYPE_CONSTANTS} from "~/lib/constants";
import {MetaWeblogApi} from "~/lib/platform/metaweblog/metaweblogApi";
import {IApi} from "~/lib/api";

/**
* JVue的API适配器
*/
export class JvueApiAdaptor extends MetaWeblogApiAdaptor implements IApi {
private readonly env:any

constructor(env:any) {
super();

this.env = env
this.apiUrl = env.JVUE_API_URL || ""
this.username = env.JVUE_USERNAME || ""
this.password = env.JVUE_PASSWORD || ""
this.appkey = API_TYPE_CONSTANTS.API_TYPE_JVUE

this.metaWeblog = new MetaWeblogApi(this.appkey, this.apiUrl, this.username, this.password);
}
}
Loading

0 comments on commit 509a194

Please sign in to comment.