diff --git a/CHANGELOG.md b/CHANGELOG.md index a44a1396c..a2545db55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.2.0 + +### Features +- Add `Google Analytics` plugin. + ## 2.1.0 ### Features - Add search plugin diff --git a/README.md b/README.md index b5d7e09a8..a1f126183 100644 --- a/README.md +++ b/README.md @@ -76,13 +76,12 @@ These open-source projects are using docsify to generate their sites. Pull reque ## Development -### prepare ```bash npm i && npm run dev open http://localhost:3000 ``` -### More Language Highlight +## More Language Highlight ```html diff --git a/build/build.js b/build/build.js index 62314e585..cbeefc929 100644 --- a/build/build.js +++ b/build/build.js @@ -47,3 +47,14 @@ isProd && build({ moduleName: 'D.Search', plugins: [uglify()] }) +build({ + entry: 'plugins/ga.js', + output: 'plugins/ga.js', + moduleName: 'D.GA' +}) +isProd && build({ + entry: 'plugins/ga.js', + output: 'plugins/ga.min.js', + moduleName: 'D.GA', + plugins: [uglify()] +}) diff --git a/docs/README.md b/docs/README.md index 8a1eb9ec6..5be78842d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -468,7 +468,7 @@ If a document can have a search, can enhance some user experience. Installing th ```html - + ``` @@ -495,3 +495,20 @@ window.$docsify = { } } ``` + +### Google Analytics + +Install the plugin and configure the track id. + +```html + + +``` + +or + +```js +window.$docsify = { + ga: 'UA-XXXXX-Y' +} +``` diff --git a/docs/_coverpage.md b/docs/_coverpage.md index 42151edb1..03edc5cb5 100644 --- a/docs/_coverpage.md +++ b/docs/_coverpage.md @@ -1,6 +1,6 @@ ![logo](_media/icon.svg) -# docsify 2.1.0 +# docsify 2.2.0 > A magical documentation site generator. diff --git a/docs/zh-cn.md b/docs/zh-cn.md index 0b193953f..0a1405859 100644 --- a/docs/zh-cn.md +++ b/docs/zh-cn.md @@ -501,3 +501,20 @@ window.$docsify = { } } ``` + +### Google Analytics + +安装插件并且配置 track id。 + +```html + + +``` + +或者 + +```js +window.$docsify = { + ga: 'UA-XXXXX-Y' +} +``` diff --git a/lib/docsify.js b/lib/docsify.js index de4fbb9bb..26f8a1d89 100644 --- a/lib/docsify.js +++ b/lib/docsify.js @@ -2799,7 +2799,8 @@ var OPTIONS = merge({ auto2top: false, name: '', themeColor: '', - nameLink: window.location.pathname + nameLink: window.location.pathname, + ga: '' }, window.$docsify); var script = document.currentScript || [].slice.call(document.getElementsByTagName('script')).pop(); diff --git a/lib/docsify.min.js b/lib/docsify.min.js index af15fe489..d11e9ee2b 100644 --- a/lib/docsify.min.js +++ b/lib/docsify.min.js @@ -1,2 +1,2 @@ var D=function(){"use strict";function e(e,t,n){void 0===t&&(t="GET");var r=new XMLHttpRequest;return r.open(t,e),r.send(),{then:function(e,t){if(void 0===t&&(t=function(){}),n){var i=setInterval(function(e){return n({step:Math.floor(5*Math.random()+1)})},500);r.addEventListener("progress",n),r.addEventListener("loadend",function(e){n(e),clearInterval(i)})}r.addEventListener("error",t),r.addEventListener("load",function(n){var r=n.target;r.status>=400?t(r):e(r.response)})},abort:function(){return 4!==r.readyState&&r.abort()}}}function t(e,t){var n=[],r={};return e.forEach(function(e){var i=e.level||1,a=i-1;i>t||(r[a]?(r[a].children=r[a].children||[],r[a].children.push(e)):n.push(e),r[i]=e)}),n}function n(e){return e.replace(/([A-Z])/g,function(e){return"-"+e.toLowerCase()})}function r(e){return null===e||void 0===e}function i(){var e=window.location;if(M===e.hash&&!r(j))return j;var t=e.hash.replace(/%23/g,"#").match(/^#\/([^#]+)/);return t=t&&2===t.length?t[1]:/^#\//.test(e.hash)?"":e.pathname,j=t,M=e.hash,t}function a(){return document.body.clientWidth<=600}function o(e){var t=/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,.\/:;<=>?@\[\]^`{|}~]/g,n=!1,r="-";if(o.occurrences=o.occurrences||{},"string"!=typeof e)return"";n||(e=e.toLowerCase());var i=e.trim().replace(/<[^>\d]+>/g,"").replace(t,"").replace(/\s/g,r).replace(/-+/g,r).replace(/^(\d)/,"_$1"),a=o.occurrences[i];return o.occurrences.hasOwnProperty(i)?a++:a=0,o.occurrences[i]=a,a&&(i=i+"-"+a),i}function s(e){return e.replace(/<(pre|template)[^>]*?>([\s\S]+)<\/(pre|template)>/g,function(e){return e.replace(/:/g,"__colon__")}).replace(/:(\w*?):/gi,'$1').replace(/__colon__/g,":")}function l(){function e(){for(var e,a=document.body.scrollTop,s=0,c=n.length;sa){e||(e=u);break}e=u}if(e){var p=o[e.getAttribute("data-id")];if(p&&p!==l&&(l&&l.classList.remove("active"),p.classList.add("active"),l=p,!t&&!g.noSticky)){var d=0,h=l.offsetTop+l.clientHeight+40,f=l.offsetTop>=r.scrollTop&&h<=r.scrollTop+i,m=h-d=e||g.dom.classList.contains("hidden")?(document.body.classList.add("sticky"),g.noSticky=!1):(document.body.classList.remove("sticky"),g.noSticky=!0)}()}function h(e,t){return t={exports:{}},e(t,t.exports),t.exports}function f(e){return e?(/\/\//.test(e)||(e="https://github.com/"+e),e=e.replace(/^git\+/,""),'\n \n \n '):""}function m(){var e=b()+'';return(a()?e+"
":"
"+e)+'
\n
\n
\n
'}function y(){var e=", 100%, 85%",t="linear-gradient(to left bottom, hsl("+(Math.floor(255*Math.random())+e)+") 0%, hsl("+(Math.floor(255*Math.random())+e)+") 100%)";return'
\n
\n
\n
'}function b(){return''}function v(e,t){return void 0===t&&(t=""),e&&e.length?(e.forEach(function(e){t+='
  • '+e.title+"
  • ",e.children&&(t+='
    • '+v(e.children)+"
    ")}),t):""}function k(e,t){return'

    '+t.slice(5).trim()+"

    "}function w(e){return""}function x(e){e.innerHTML=e.innerHTML.replace(/var\(\s*--theme-color.*?\)/g,$docsify.themeColor)}function L(){if(!(window.CSS&&window.CSS.supports&&window.CSS.supports("(--foo: red)"))){var t=document.querySelectorAll("style:not(.inserted),link");[].forEach.call(t,function(t){if("STYLE"===t.nodeName)x(t);else if("LINK"===t.nodeName){var n=t.getAttribute("href");if(!/\.css$/.test(n))return;e(n).then(function(e){var t=document.createElement("style");t.innerHTML=e,document.head.appendChild(t),x(t)})}})}}function S(){var e=new F.Renderer;e.heading=function(e,t){var n=o(e),r="";return r="#/"+i(),H.push({level:t,slug:r+"#"+encodeURIComponent(n),title:e}),"'+e+""},e.code=function(e,t){void 0===t&&(t="");var n=W.highlight(e,W.languages[t]||W.languages.markup);return'
    '+n+"
    "},e.link=function(e,t,n){return/:/.test(e)||(e=("#/"+e).replace(/\/+/g,"/")),''+n+""},e.paragraph=function(e){return/^!>/.test(e)?k("tip",e):/^\?>/.test(e)?k("warn",e):"

    "+e+"

    "},"function"==typeof $docsify.markdown?(z.setOptions({renderer:e}),z=$docsify.markdown.call(this,z)):z.setOptions(O({renderer:e},$docsify.markdown));var t=z;z=function(e){return s(t(e))},window.Docsify.utils.marked=function(e){var t=z(e);return H=[],t}}function $(e,t){var n=document.querySelector("nav")||document.createElement("nav"),r=document.body,i=document.head;if($docsify.repo||n.classList.add("no-badge"),e[t?"outerHTML":"innerHTML"]=f($docsify.repo)+($docsify.coverpage?y():"")+m(),r.insertBefore(n,r.children[0]),$docsify.themeColor&&(i.innerHTML+=w($docsify.themeColor),L()),$docsify.name){var o=document.querySelector(".sidebar");o.innerHTML='

    '+$docsify.name+"

    "+o.innerHTML}p("button.sidebar-toggle"),$docsify.coverpage?!a()&&window.addEventListener("scroll",g):r.classList.add("sticky")}function _(e){if(D("article",e?z(e):"not found"),$docsify.loadSidebar||E(),e&&"undefined"!=typeof Vue){R.vm&&R.vm.$destroy();var t=[].slice.call(document.body.querySelectorAll("article>script")).filter(function(e){return!/template/.test(e.type)})[0],n=t?t.innerText.trim():null;t&&t.remove(),R.vm=n?new Function("return "+n)():new Vue({el:"main"}),R.vm&&R.vm.$nextTick(function(e){return l()})}$docsify.auto2top&&setTimeout(function(){return d($docsify.auto2top)},0)}function C(e){R.navbar&&R.navbar===e||(R.navbar=e,e&&D("nav",z(e)),u("nav"))}function E(e){var n;e?(n=z(e),n=n.match(/]*>([\s\S]+)<\/ul>/g)[0]):n=v(t(H,$docsify.maxLevel),"