From 03016cadbc970df52b86e45521b9b0e2a043a952 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Tue, 12 Oct 2021 19:05:00 +0800 Subject: [PATCH] feat: add wwads plugin. --- docusaurus.config.js | 5 +---- src/plugins/plugin-wwads/index.js | 27 +++++++++++++++++++++++++++ src/plugins/plugin-wwads/wwads.js | 20 ++++++++++++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 src/plugins/plugin-wwads/index.js create mode 100644 src/plugins/plugin-wwads/wwads.js diff --git a/docusaurus.config.js b/docusaurus.config.js index 65c42a6..cee0911 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -232,6 +232,7 @@ const darkCodeTheme = require("prism-react-renderer/themes/palenight"); ], }, ], + "./src/plugins/plugin-wwads/index.js", ], scripts: [ { @@ -240,10 +241,6 @@ const darkCodeTheme = require("prism-react-renderer/themes/palenight"); defer: true, "data-website-id": "7e8d48ad-973d-4b44-b36d-ea1f1df25baa", }, - { - src: "https://cdn.wwads.cn/js/makemoney.js", - async: true, - }, { src: "/js/wwads.js", }, diff --git a/src/plugins/plugin-wwads/index.js b/src/plugins/plugin-wwads/index.js new file mode 100644 index 0000000..e653460 --- /dev/null +++ b/src/plugins/plugin-wwads/index.js @@ -0,0 +1,27 @@ +const path = require("path"); + +function pluginWwads() { + return { + name: "docusaurus-plugin-wwads", + + getClientModules() { + return [path.resolve(__dirname, "./wwads")]; + }, + + injectHtmlTags() { + return { + headTags: [ + { + tagName: "script", + attributes: { + async: true, + src: `https://cdn.wwads.cn/js/makemoney.js`, + }, + }, + ], + }; + }, + }; +} + +exports.default = pluginWwads; diff --git a/src/plugins/plugin-wwads/wwads.js b/src/plugins/plugin-wwads/wwads.js new file mode 100644 index 0000000..4413162 --- /dev/null +++ b/src/plugins/plugin-wwads/wwads.js @@ -0,0 +1,20 @@ +import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment"; + +export default (function () { + if (!ExecutionEnvironment.canUseDOM) { + return null; + } + + return { + onRouteUpdate() { + setTimeout(() => { + const ad = document.getElementsByClassName("table-of-contents"); + const adnode = document.createElement("div"); + adnode.setAttribute("class", "wwads-cn wwads-vertical"); + adnode.setAttribute("data-id", "80"); + adnode.setAttribute("style", "max-width:200px"); + ad[0].parentNode.appendChild(adnode); + }, 2000); + }, + }; +})();