Comments (4)
可以的,看能不能在现有的图床方案扩展
from yuque-hexo.
我实现了一个非常简单的,勉强能用的版本。仅供参考(不好意思提pr,感觉我js写的不太好)
diff --git a/node_modules/yuque-hexo/adapter/hexo.js b/node_modules/yuque-hexo/adapter/hexo.js
index b42469a..9422c21 100644
--- a/node_modules/yuque-hexo/adapter/hexo.js
+++ b/node_modules/yuque-hexo/adapter/hexo.js
@@ -35,7 +35,7 @@ function parseMatter(body) {
body = entities.decode(body);
try {
// front matter信息的<br/>换成 \n
- const regex = /(title:|layout:|tags:|date:|categories:){1}(\S|\s)+?---/gi;
+ const regex = /(title:|layout:|tags:|date:|categories:|toc:){1}(\S|\s)+?---/gi;
body = body.replace(regex, a =>
a.replace(/(<br \/>|<br>|<br\/>)/gi, '\n')
);
@@ -76,6 +76,7 @@ module.exports = async function(post) {
const date = data.date || formatDate(created_at);
const tags = data.tags || [];
const categories = data.categories || [];
+ const toc = data.toc || true;
const props = {
title: title.replace(/"/g, ''), // 临时去掉标题中的引号,至少保证文章页面是正常可访问的
urlname,
@@ -83,6 +84,7 @@ module.exports = async function(post) {
...data,
tags,
categories,
+ toc,
};
const text = ejs.render(template, {
raw,
diff --git a/node_modules/yuque-hexo/util/imageBeds/index.js b/node_modules/yuque-hexo/util/imageBeds/index.js
index 4af4909..9cac9a3 100644
--- a/node_modules/yuque-hexo/util/imageBeds/index.js
+++ b/node_modules/yuque-hexo/util/imageBeds/index.js
@@ -5,10 +5,11 @@ const OssClient = require('./oss');
const QiniuClient = require('./qiniu');
const UPClient = require('./upyun');
const GithubClient = require('./github');
+const LocalClient = require("./local");
const out = require('../../lib/out');
// 目前已适配图床列表
-const imageBedList = [ 'qiniu', 'cos', 'oss', 'upyun', 'github' ];
+const imageBedList = [ 'qiniu', 'cos', 'oss', 'upyun', 'github', 'local' ];
class ImageBeds {
constructor(config) {
@@ -45,6 +46,8 @@ class ImageBeds {
return UPClient.getInstance(this.config);
case 'github':
return GithubClient.getInstance(this.config);
+ case 'local':
+ return LocalClient.getInstance(this.config);
default:
return QiniuClient.getInstance(this.config);
}
diff --git a/node_modules/yuque-hexo/util/imageBeds/local.js b/node_modules/yuque-hexo/util/imageBeds/local.js
new file mode 100644
index 0000000..9224ee4
--- /dev/null
+++ b/node_modules/yuque-hexo/util/imageBeds/local.js
@@ -0,0 +1,45 @@
+'use strict';
+
+const out = require('../../lib/out');
+const fs = require("fs");
+
+class LocalClient {
+ constructor(config) {
+ this.config = config;
+ }
+
+ static getInstance(config) {
+ if (!this.instance) {
+ this.instance = new LocalClient(config);
+ }
+ return this.instance;
+ }
+
+ async hasImage(fileName) {
+ try {
+ const cwd = process.cwd();
+ const imgDir = `${cwd}/source/images`
+ const imgUrl = `/images/${fileName}`
+ if (fs.existsSync(`${imgDir}/${fileName}`)) {
+ return imgUrl
+ }
+ } catch(e) {
+ return '';
+ }
+ }
+
+ async uploadImg(imgBuffer, fileName) {
+ const imgDir = `${process.cwd()}/source/images`
+ const imgPath = `${imgDir}/${fileName}`
+ const imgUrl = `/images/${fileName}`
+
+ if (!fs.existsSync(imgDir)) {
+ fs.mkdirSync(imgDir)
+ }
+
+ fs.writeFileSync(imgPath, imgBuffer)
+ return imgUrl
+ }
+}
+
+module.exports = LocalClient;
from yuque-hexo.
+10086, 太需要这个功能了, 上传github图床这个操作其实是多此一举, 只会遇到一堆网络错误
from yuque-hexo.
有相关进度吗,真的很需要这个,感谢大佬们
from yuque-hexo.
Related Issues (20)
- 上传七牛云图床部分图片上次失败,无法准确定位到具体问题 HOT 1
- 用七牛云上传图片,但是图片损坏了,不知道那里出问题了 HOT 7
- 可以自动上传到又拍云 图床么 HOT 2
- 语雀图片转换失败 HOT 3
- 教程描述有待提升 HOT 5
- 请求添加自动分组功能 HOT 2
- 建议同步语雀文档的修改时间 HOT 4
- github actions的lastGeneratePath.log问题 HOT 6
- 最近发现自动上传到图床的图片大小都不正确,无法正常显示怎么排查? HOT 4
- 发现隔一段时间(一到两周)就部署失败,重置了yuque_token后正常 HOT 3
- 关于 adpater (hexo) is invalid. 的问题 HOT 11
- 自定义 front-matter 异常
- 语雀分享要会员了,可以出一个飞书的吗
- 是否可以保留hexo写博客的能力? HOT 2
- 图片替换失败
- yuque-hexo相关逻辑 HOT 1
- [WARNING] 检查图片信息时出错
- 现在没有会员咋设置token HOT 2
- use slug as permant_link title HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yuque-hexo.