Fix up links to other wiki-doc pages, and reduce the following depth to improve load times.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4631 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2023-11-14 17:38:48 +00:00
parent 305f5232e7
commit a0043ec49f
3 changed files with 17 additions and 2 deletions

View File

@ -1,5 +1,5 @@
{
"type": "tildefriends-app",
"emoji": "📝",
"previous": "&HpEPHrCdoej769DCZmJYH0ma9OfzdhPKMTEmvcNz8Wg=.sha256"
"previous": "&FINPRELEEbBO4wVoRYZyd5/VIMERFMyk4NjC8wxjelE=.sha256"
}

View File

@ -39,7 +39,7 @@ class TfCollectionsAppElement extends LitElement {
this.owner_ids = await tfrpc.rpc.getOwnerIdentities();
this.whoami = await tfrpc.rpc.localStorageGet('collections_whoami');
let ids = [...new Set([...this.owner_ids, this.whoami])].sort();
this.following = Object.keys(await tfrpc.rpc.following(ids, 2)).sort();
this.following = Object.keys(await tfrpc.rpc.following(ids, 1)).sort();
await this.read_wikis();
await this.read_Wiki_docs();
@ -281,6 +281,7 @@ class TfCollectionsAppElement extends LitElement {
${this.wiki_doc && this.wiki_doc.parent === this.wiki?.id ? html`
<tf-wiki-doc
whoami=${this.whoami}
.wiki=${this.wiki}
.value=${this.wiki_doc}></tf-wiki-doc>
` : undefined}
`;

View File

@ -5,6 +5,7 @@ class TfWikiDocElement extends LitElement {
static get properties() {
return {
whoami: {type: String},
wiki: {type: String},
value: {type: Object},
blob: {type: String},
blob_original: {type: String},
@ -21,6 +22,19 @@ class TfWikiDocElement extends LitElement {
var reader = new commonmark.Parser({safe: true});
var writer = new commonmark.HtmlRenderer();
var parsed = reader.parse(md || '');
let walker = parsed.walker();
let event;
while ((event = walker.next())) {
let node = event.node;
if (event.entering) {
if (node.type === 'link') {
if (node.destination.indexOf(':') == -1 &&
node.destination.indexOf('/') == -1) {
node.destination = `#${this.wiki?.name}/${node.destination}`;
}
}
}
}
return writer.render(parsed);
}