-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
784 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import {SiYuanApiAdaptor} from "~/lib/siyuan/siYuanApiAdaptor"; | ||
import {API_TYPE_CONSTANTS} from "~/lib/constants"; | ||
import {Post} from "~/lib/common/post"; | ||
import {UserBlog} from "~/lib/common/userBlog"; | ||
|
||
export interface IApi { | ||
/** | ||
* 博客配置列表 | ||
*/ | ||
getUsersBlogs(): Promise<Array<UserBlog>> | ||
|
||
/** | ||
* 最新文章 | ||
* @param numOfPosts 文章数目 | ||
* @param page 页码(可选,部分平台不支持分页) | ||
* @param keyword 关键字(可选,部分平台不支持搜索) | ||
*/ | ||
getRecentPosts(numOfPosts: number, page?: number, keyword?: string): Promise<Array<any>> | ||
|
||
/** | ||
* 文章详情 | ||
* @param postid | ||
* @param useSlug 是否使用的是别名(可选,部分平台不支持) | ||
*/ | ||
getPost(postid: string, useSlug?: boolean): Promise<any> | ||
} | ||
|
||
export class API implements IApi { | ||
type: string | ||
private apiAdaptor: IApi | ||
|
||
constructor(type: string, env: any) { | ||
this.type = type; | ||
switch (this.type) { | ||
case API_TYPE_CONSTANTS.API_TYPE_SIYUAN: | ||
this.apiAdaptor = new SiYuanApiAdaptor(env) | ||
break; | ||
default: | ||
throw new Error("未找到接口适配器,请检查参数") | ||
} | ||
} | ||
|
||
async getRecentPosts(numOfPosts: number, page?: number, keyword?: string): Promise<Array<Post>> { | ||
return this.apiAdaptor.getRecentPosts(numOfPosts, page, keyword); | ||
} | ||
|
||
async getUsersBlogs(): Promise<Array<UserBlog>> { | ||
return this.apiAdaptor.getUsersBlogs(); | ||
} | ||
|
||
getPost(postid: string, useSlug?: boolean): Promise<Post> { | ||
return this.apiAdaptor.getPost(postid, useSlug); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* 通用文章模型定义 | ||
*/ | ||
import {POST_STATUS_CONSTANTS} from "~/lib/constants/postStatusConstants"; | ||
|
||
export class Post { | ||
postid: string | ||
title: string | ||
/** | ||
* 逗号分隔的标签 | ||
*/ | ||
mt_keywords: string | ||
link?: string | ||
permalink: string | ||
shortDesc?:string | ||
description: string | ||
mt_excerpt?: string | ||
wp_slug: string | ||
dateCreated: Date | ||
categories: Array<string> | ||
mt_text_more?: string | ||
post_status?:string | ||
isPublished: boolean | ||
wp_password: string | ||
|
||
constructor() { | ||
this.postid = "" | ||
this.title = "" | ||
this.mt_keywords = "" | ||
this.permalink = "" | ||
this.description = "" | ||
this.wp_slug = "" | ||
this.dateCreated = new Date() | ||
this.categories = [] | ||
this.isPublished = true | ||
this.post_status = POST_STATUS_CONSTANTS.POST_STATUS_PUBLISH | ||
this.wp_password = "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {UserBlog} from "./userBlog"; | ||
|
||
export default class SiteConfig { | ||
userBlog: UserBlog | ||
|
||
domain: string | ||
weburl: string | ||
webtheme: string | ||
webname: string | ||
webslogen: string | ||
keywords: string | ||
description: string | ||
beianinfo: string | ||
|
||
constructor() { | ||
this.userBlog = new UserBlog(); | ||
this.domain = "" | ||
this.weburl = "" | ||
this.webtheme = "default" | ||
this.webname = "浅海拾贝" | ||
this.webslogen = "寻找未知的技术拼图" | ||
this.keywords = "软件架构、服务端开发、Java、Spring、Dubbo、Zookeeper、微服务" | ||
this.description = "浅海拾贝是关注与分享互联网及服务端开发技术的个人博客,致力于Java后端开发及服务端技术、软件架构、微服务技术分享。同时也记录个人的一路点滴,所蕴含的包括前端、后端、数据库等知识,欢迎您关注我。" | ||
this.beianinfo = "粤ICP备18023717号-1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export class UserBlog { | ||
blogid: string | ||
url: string | ||
blogName: string | ||
isAdmin?: boolean | ||
xmlrpc?: string | ||
|
||
|
||
constructor() { | ||
this.blogid = ""; | ||
this.url = ""; | ||
this.blogName = "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* 思源笔记 | ||
*/ | ||
const API_TYPE_SIYUAN = "siyuan" | ||
|
||
/** | ||
* API类型常量定义 | ||
*/ | ||
export const API_TYPE_CONSTANTS = { | ||
API_TYPE_SIYUAN | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const GET_USERS_BLOGS = "blogger.getUsersBlogs" | ||
const NEW_POST = "metaWeblog.newPost" | ||
const EDIT_POST = "metaWeblog.editPost" | ||
const DELETE_POST = "blogger.deletePost" | ||
const GET_RECENT_POSTS = "metaWeblog.getRecentPosts" | ||
const GET_POST = "metaWeblog.getPost" | ||
|
||
export const METAWEBLOG_METHOD_CONSTANTS = { | ||
GET_USERS_BLOGS, | ||
NEW_POST, | ||
EDIT_POST, | ||
DELETE_POST, | ||
GET_RECENT_POSTS, | ||
GET_POST | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const POST_STATUS_PUBLISH = "publish" | ||
const POST_TYPE_DRAFT = "draft" | ||
const POST_TYPE_INHERIT = "inherit" | ||
|
||
export const POST_STATUS_CONSTANTS = { | ||
POST_STATUS_PUBLISH, | ||
POST_TYPE_DRAFT, | ||
POST_TYPE_INHERIT | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const SERVER_API_GET_RECENT_POSTS = "/api/endpoint/getRecentPosts" | ||
const SERVER_API_GET_POST = "/api/endpoint/getPost" | ||
|
||
export const SERVER_API_CONSTANTS = { | ||
SERVER_API_GET_RECENT_POSTS, | ||
SERVER_API_GET_POST | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// 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"; | ||
|
||
/** | ||
* 移除标题数字 | ||
* @param str | ||
*/ | ||
export function removeTitleNumber(str: string) { | ||
let newstr = str | ||
|
||
// 移除序号 | ||
const publisherRegex = /([0-9]*)\./g; | ||
newstr = newstr.replace(publisherRegex, "") | ||
|
||
return newstr | ||
} | ||
|
||
/** | ||
* 删除挂件的HTML | ||
* @param str 原字符 | ||
* @returns {*|string} 删除后的字符 | ||
*/ | ||
export function removeWidgetTag(str: string) { | ||
let newstr = str | ||
|
||
// 旧版发布挂件 | ||
const publisherRegex = /<iframe.*src="\/widgets\/publisher.*<\/iframe>/g; | ||
newstr = newstr.replace(publisherRegex, "") | ||
|
||
// 新版发布挂件 | ||
const syPublisherRegex = /<iframe.*src="\/widgets\/sy-post-publisher.*<\/iframe>/g; | ||
newstr = newstr.replace(syPublisherRegex, "") | ||
|
||
// 文章属性挂件 | ||
const noteAttrRegex = /<iframe.*\/widgets\/Note*\sAttrs.*\/iframe>/g | ||
newstr = newstr.replace(noteAttrRegex, "") | ||
|
||
const h1Regex = /<h1.*\/h1>/g | ||
newstr = newstr.replace(h1Regex, "") | ||
|
||
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 | ||
* @returns {string} 转换后的结果 | ||
*/ | ||
function filterHtml(str: string) { | ||
/* | ||
* <.*?>为正则表达式,其中的.表示任意字符,*?表示出现0次或0次以上,此方法可以去掉双头标签(双头针对于残缺的标签) | ||
* "<.*?"表示<尖括号后的所有字符,此方法可以去掉残缺的标签,及后面的内容 | ||
* " ",若有多种此种字符,可用同一方法去除 | ||
*/ | ||
str = str.replace(/<style((.|\n|\r)*?)<\/style>/g, '') | ||
str = str.replace(/<script((.|\n|\r)*?)<\/script>/g, '') | ||
str = str.replace(/<[^>]*>/g, ''); | ||
str = str.replace(/&.*;/g, ''); | ||
str = str.replace(/(^\s*)|(\s*$)/g, ""); | ||
str = str.replace(/</g, "").replace(/>/g, "") | ||
str = str.replace(/"/g, "").replace(/'/g, "") | ||
|
||
// 正则保留字符 | ||
str = str.replace(/\*/g, "") | ||
str = str.replace(/\$/g, "") | ||
str = str.replace(/\./g, "") | ||
str = str.replace(/\+/g, "") | ||
|
||
// 下面是行内空格,不建议去除 | ||
str = str.replace(/\s+/g, ''); | ||
|
||
// 冒号分号替换成下划线 | ||
str = str.replace(/[:|:]/g, "_") | ||
str = str.replace(/[;|;]/g, "_") | ||
|
||
// 需要排除的字符 | ||
const excludeWords = ['\\d*/\\d/\\d*', '[、|\\\\]', '[,|,]', '\\d', '/', '-'] | ||
for (let i = 0; i < excludeWords.length; i++) { | ||
const regex = new RegExp(excludeWords[i], "g"); | ||
str = str.replaceAll(regex, "") | ||
} | ||
|
||
str = str.toLowerCase(); | ||
return str; | ||
} | ||
|
||
/** | ||
* 将Markdown转换为纯文本 | ||
* @param md | ||
* @returns {string} | ||
*/ | ||
export function mdToPlanText(md: string) { | ||
let html = renderHTML(md) | ||
html = removeWidgetTag(html) | ||
return filterHtml(html) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// 开发阶段开启所有日志 | ||
// 发布阶段只开启WARN和ERROR日志 | ||
|
||
const LOG_INFO_ENABLED = true | ||
const LOG_WARN_ENABLED = true | ||
const LOG_ERROR_ENABLED = true | ||
|
||
/** | ||
* 信息日志 | ||
* @param msg 信息 | ||
* @param param 参数 | ||
*/ | ||
const logInfo = (msg: any, param?: any) => { | ||
if (LOG_INFO_ENABLED) { | ||
if (param) { | ||
console.log(msg) | ||
console.log(param) | ||
} else { | ||
console.log(msg) | ||
} | ||
} | ||
} | ||
/** | ||
* 警告日志 | ||
* @param msg 警告信息 | ||
* @param param 参数 | ||
*/ | ||
const logWarn = (msg: any, param?: any) => { | ||
if (LOG_WARN_ENABLED) { | ||
if (param) { | ||
console.warn(msg) | ||
console.warn(param) | ||
} else { | ||
console.warn(msg) | ||
} | ||
} | ||
} | ||
/** | ||
* 错误日志 | ||
* @param msg 错误信息 | ||
* @param param 参数 | ||
*/ | ||
const logError = (msg: any, param?: any) => { | ||
if (LOG_ERROR_ENABLED) { | ||
if (param) { | ||
console.error(msg) | ||
console.error(param) | ||
} else { | ||
console.error(msg) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* 日志记录 | ||
*/ | ||
const logUtil = { | ||
logInfo, | ||
logWarn, | ||
logError | ||
} | ||
|
||
export default logUtil |
Oops, something went wrong.