diff --git a/index.html b/index.html
index 1e112b233..ccd266270 100644
--- a/index.html
+++ b/index.html
@@ -87,7 +87,7 @@
plugins: [
DocsifyCarbon.create('CEBI6KQE', 'docsifyjsorg'),
function (hook, vm) {
- hook.beforeEach(function (html) {
+ let demo = (html, matchedPluginHooks =[]) => {
if (/githubusercontent\.com/.test(vm.route.file)) {
url = vm.route.file
.replace('raw.githubusercontent.com', 'github.com')
@@ -101,7 +101,14 @@
'https://github.com/docsifyjs/docsify/blob/develop/docs/' +
vm.route.file;
}
+
var editHtml = '[:memo: Edit Document](' + url + ')\n';
+ // matchedPluginHooks[0](editHtml)
+ matchedPluginHooks.forEach(hook=>{
+ if(typeof hook === 'function'){
+ hook(html, 10086)
+ }
+ })
return (
editHtml +
html +
@@ -109,7 +116,15 @@
'Powered by docsify\n\n' +
'
'
);
- });
+ }
+ demo.enableDocsifyPluginHook=true
+ demo.pluginMeta = {
+ name:"koy"
+ }
+ hook.beforeEach(
+ demo
+
+ );
},
],
};
diff --git a/src/core/init/lifecycle.js b/src/core/init/lifecycle.js
index 94a3981fe..c9d1d217b 100644
--- a/src/core/init/lifecycle.js
+++ b/src/core/init/lifecycle.js
@@ -1,4 +1,4 @@
-import { noop } from '../util/core';
+import { isFn, noop } from '../util/core';
/** @typedef {import('../Docsify').Constructor} Constructor */
@@ -27,24 +27,49 @@ export function Lifecycle(Base) {
});
}
- callHook(hookName, data, next = noop) {
+ callHook(hookName, data, next = noop, registeredPluginHooks = []) {
+ // let myPredictor = (meta)=>{
+ // return true;
+ // }
+
+ // let myWorker = (ctx, number) => {
+ // console.log(`Current ctx is ${ctx}`)
+ // console.log(`Current number is ${number}`)
+ // }
+ // registeredPluginHooks.push({predicator:myPredictor, operator:myWorker})
+
const queue = this._hooks[hookName];
const catchPluginErrors = this.config.catchPluginErrors;
const step = function (index) {
const hookFn = queue[index];
-
+ let matchedPluginHooks = [];
if (index >= queue.length) {
next(data);
} else if (typeof hookFn === 'function') {
const errTitle = 'Docsify plugin error';
+ // find all matched pluginHook
+
+ if (hookFn.enableDocsifyPluginHook) {
+ registeredPluginHooks.forEach(registeredPluginHook => {
+ const pluginMeta = hookFn.pluginMeta || {};
+ const hookPredicator = registeredPluginHook.predicator;
+ isFn(hookPredicator) &&
+ hookPredicator(pluginMeta) &&
+ matchedPluginHooks.push(registeredPluginHook.operator);
+ });
+ }
if (hookFn.length === 2) {
try {
- hookFn(data, result => {
- data = result;
- step(index + 1);
- });
+ hookFn(
+ data,
+ result => {
+ data = result;
+ step(index + 1);
+ },
+ matchedPluginHooks
+ );
} catch (err) {
if (catchPluginErrors) {
console.error(errTitle, err);
@@ -56,7 +81,7 @@ export function Lifecycle(Base) {
}
} else {
try {
- const result = hookFn(data);
+ const result = hookFn(data, matchedPluginHooks);
data = result === undefined ? data : result;
step(index + 1);
diff --git a/src/plugins/search/index.js b/src/plugins/search/index.js
index c3bdab96e..c1b284492 100644
--- a/src/plugins/search/index.js
+++ b/src/plugins/search/index.js
@@ -13,7 +13,7 @@ const CONFIG = {
pathNamespaces: undefined,
};
-const install = function (hook, vm) {
+const search1 = (hook, vm) => {
const { util } = Docsify;
const opts = vm.config.search || CONFIG;
@@ -43,4 +43,4 @@ const install = function (hook, vm) {
});
};
-$docsify.plugins = [].concat(install, $docsify.plugins);
+$docsify.plugins = [].concat(search1, $docsify.plugins);