importしたscrapbox pageを関連ページリストに表示する
2020-11-02 10:56:02
便利そうなので導入してみるtakker.icon
/icons/done.icon適当にアレンジした
ページ読み込み時に表示する
再読込はしない
既知の問題
他のprojectに遷移したときに残ってしまう
code:script.js
import {createPageCard} from '/api/code/takker/scrapboxのページカードを作成するscript/script.js';
const relatedPageList = document.getElementsByClassName('related-page-list clearfix')?.0; const relationLabel = `
<li class="relation-label links">
<a>
<span class="title">Dependencies</span>
<span class="kamon kamon-link-on icon-lg"></span>
</a>
<span class="arrow"></span>
</li>`;
const newList = document.createElement('ul');
newList.classList.add('grid', 'ex-code-link-list');
newList.insertAdjacentHTML('beforeend', relationLabel);
relatedPageList?.appendChild(newList);
const codelines = window.scrapbox.Page.lines.filter(line => line.codeBlock);
const dependencies = codelines.reduce((acc, line) => {
const text = line.text.trim();
const matched = text.match(/^import\s(\'|\")(.+)(\'|\")/);
if (matched) {
}
return acc;
}, []);
//console.log(dependencies);
dependencies.forEach(async path => {
path = path.replace(/^\/api\/code\/(^\/+)\/(^\/+)\/.*$/, '$1/$2'); const page = await fetch(/api/pages/${path})
.then(res => res.json());
//console.log(page);
newList.insertAdjacentHTML('beforeend',createPageCard({
project: scrapbox.Project.name,
title: page.title,
description: page.descriptions.join('\n'),
imageUrl: page.image}));
});
if (newList.children.length < 2) newList.style.display='none';