From 01b487c426f999cfa63e5ee851b78f0cc847b96f Mon Sep 17 00:00:00 2001 From: CyC2018 Date: Sat, 31 Oct 2026 20:17:09 +0800 Subject: [PATCH] Update site.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 学习站中有题的笔记在文章末尾加“读完练一练”的入口。 --- website/templates/site.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/website/templates/site.js b/website/templates/site.js index c4c14f11..8da3a586 100644 --- a/website/templates/site.js +++ b/website/templates/site.js @@ -205,6 +205,19 @@ var heading = section.querySelector('h1'); (heading || section.firstChild).insertAdjacentElement(heading ? 'afterend' : 'beforebegin', box); } + // 学习站中有这篇笔记的题时,文章末尾提示读完练一练(只抽这篇笔记的题,还没开始学也可以练) + function practiceCallout(vm, section) { + var match = decode(vm.route.path).match(/^\/notes\/(.+)$/), note = match && match[1]; + var count = note && (window.CS_NOTES_LEARN_TOPICS || {})[note]; + if (!section || !count || count < 2 || section.querySelector('.learn-practice')) return; + var box = document.createElement('a'); + box.className = 'learn-callout learn-practice'; + box.href = '/learn/#/mock/' + encodeURIComponent(note); + box.innerHTML = '读完练一练学习站中有 ' + count + ' 道和这篇笔记有关的面试题:先自己答,再对照参考要点自评,自评过的题会按间隔提醒复习。'; + // 放在上一篇、下一篇之前 + var after = section.querySelector('.page-nav') || section.querySelector('.site-footer'); + if (after) after.insertAdjacentElement('beforebegin', box); else section.appendChild(box); + } window.$docsify = { name: 'CS-Notes', repo: 'https://github.com/CyC2018/CS-Notes', @@ -239,6 +252,7 @@ stepAnimations(document.querySelector('.markdown-section')); articleToc(vm); learnCallout(vm, document.querySelector('.markdown-section')); + practiceCallout(vm, document.querySelector('.markdown-section')); document.querySelectorAll('.article-toc').forEach(function (toc) { toc.open = window.matchMedia('(min-width: 769px)').matches; });