config.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. function getTimestamp() {return parseInt(new Date() / 1000, 10);
  2. }
  3. function setReadState() {
  4. localStorage.setItem('leader.url', location.href);
  5. localStorage.setItem('leader.top', document.documentElement.scrollTop || document.body.scrollTop);
  6. setTimeout(setReadState, 5000);
  7. }
  8. function getReadState() {
  9. if (window.localStorage) {
  10. if (document.referrer === '') {
  11. var url = localStorage.getItem('leader.url');
  12. if (!!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) && url && location.href !== url) {
  13. location.href = url;
  14. setTimeout(window.scrollTo(0, ~~localStorage.getItem('leader.top')), 300);
  15. }
  16. setTimeout(setReadState, 5000);
  17. }
  18. }
  19. }
  20. // Docsify 配置
  21. window.$docsify = {
  22. name: '《团队领袖培养计划》',
  23. repo: 'https://github.com/willin/leader.js.cool.git',
  24. loadSidebar: true,
  25. subMaxLevel: 2,
  26. formatUpdated: '{YYYY}-{MM}-{DD} {HH}:{mm}',
  27. executeScript: true,
  28. auto2top: true,
  29. alias: {
  30. '/basic/_sidebar.md': '/_sidebar.md',
  31. '/basic/algorithm/_sidebar.md': '/_sidebar.md',
  32. '/basic/db/_sidebar.md': '/_sidebar.md',
  33. '/basic/framework/_sidebar.md': '/_sidebar.md',
  34. '/basic/js/_sidebar.md': '/_sidebar.md',
  35. '/basic/knowledge/_sidebar.md': '/_sidebar.md',
  36. '/basic/md/_sidebar.md': '/_sidebar.md',
  37. '/basic/node/_sidebar.md': '/_sidebar.md',
  38. '/basic/resource/_sidebar.md': '/_sidebar.md',
  39. '/experience/_sidebar.md': '/_sidebar.md',
  40. '/experience/advanced/_sidebar.md': '/_sidebar.md',
  41. '/experience/azure/_sidebar.md': '/_sidebar.md',
  42. '/experience/design/_sidebar.md': '/_sidebar.md',
  43. '/experience/operation/_sidebar.md': '/_sidebar.md',
  44. '/experience/project/_sidebar.md': '/_sidebar.md',
  45. '/experience/project/user/_sidebar.md': '/_sidebar.md',
  46. '/mind/_sidebar.md': '/_sidebar.md',
  47. '/mind/capability/_sidebar.md': '/_sidebar.md',
  48. '/mind/team/_sidebar.md': '/_sidebar.md',
  49. '/mind/thinking/_sidebar.md': '/_sidebar.md'
  50. },
  51. search: {
  52. placeholder: '搜索',
  53. noData: '未找到结果'
  54. },
  55. plugins: [
  56. function (hook, vm) {
  57. hook.init(function () {
  58. getReadState();
  59. if (typeof mermaid !== 'undefined') { mermaid.initialize({ startOnLoad: false }); }
  60. var adScript = document.createElement('script');
  61. adScript.src = '//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js';
  62. adScript.setAttribute('async', true);
  63. document.body.appendChild(adScript);
  64. });
  65. hook.beforeEach(function (md) {
  66. var url = 'https://github.com/willin/leader.js.cool/blob/master' + vm.route.file
  67. var editUrl = '[:memo: 编辑本章节](' + url + ')\n'
  68. return md
  69. + '\n----\n'
  70. + '最后更新 {docsify-updated}'
  71. + editUrl
  72. });
  73. hook.doneEach(function () {
  74. if (typeof mermaid !== 'undefined') { mermaid.init(undefined, '.mermaid') };
  75. var main = document.getElementById('main');
  76. var paragraphs = main.getElementsByTagName('p');
  77. var ads = [];
  78. if (paragraphs.length > 15) {
  79. ads.push(paragraphs[Math.ceil(Math.random() * 15)]);
  80. }
  81. ads.push(paragraphs[paragraphs.length - 1]);
  82. for (var i = 0; i < ads.length; i += 1) {
  83. ads[i].insertAdjacentHTML('afterend', '<ins class="adsbygoogle"style="display:block;margin: 1.5em auto;"data-ad-client="ca-pub-5059418763237956"data-ad-slot="9518721243"data-ad-format="auto"></ins>');
  84. (adsbygoogle = window.adsbygoogle || []).push({});
  85. }
  86. ga('send', 'pageview', location.hash.replace('#', ''));
  87. });
  88. }
  89. ],
  90. markdown: {
  91. renderer: {
  92. code: function (code, lang) {
  93. var html = '';
  94. if (code.match(/^sequenceDiagram/) || code.match(/^graph/) || code.match(/^gantt/)) {
  95. html = '<div class="mermaid">' + code + '</div>';
  96. }
  97. var hl = Prism.highlight(code, Prism.languages[lang] || Prism.languages.markup)
  98. return html + '<pre v-pre data-lang="' + lang + '"><code class="lang-'+ lang +'">'+ hl +'</code></pre>'
  99. }
  100. }
  101. }
  102. };
  103. // 离线浏览
  104. if (typeof navigator.serviceWorker !== 'undefined') {
  105. navigator.serviceWorker.register('sw.js');
  106. }
  107. (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  108. (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  109. m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  110. })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  111. ga('create', 'UA-33096931-4', 'auto');
  112. ga('send', 'pageview');