Git Product home page Git Product logo

Comments (4)

x-cold avatar x-cold commented on August 10, 2024

可以的,看能不能在现有的图床方案扩展

from yuque-hexo.

codeskyblue avatar codeskyblue commented on August 10, 2024

我实现了一个非常简单的,勉强能用的版本。仅供参考(不好意思提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.

JasonMa0012 avatar JasonMa0012 commented on August 10, 2024

+10086, 太需要这个功能了, 上传github图床这个操作其实是多此一举, 只会遇到一堆网络错误

from yuque-hexo.

ZY945 avatar ZY945 commented on August 10, 2024

有相关进度吗,真的很需要这个,感谢大佬们

from yuque-hexo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.