as promised, obliterate renderASTMap from orbit

This commit is contained in:
Jill 2023-05-18 04:23:00 +03:00
parent 56bf08de16
commit 2f7d5e0930
Signed by: oat
GPG Key ID: 33489AA58A955108
5 changed files with 512 additions and 527 deletions

View File

@ -18,7 +18,7 @@
pname = "cohost-blogger";
inherit (package) version;
npmDepsHash = "sha256-VSEkIBeF3FSYI8FbvgskznPmlqavM6g4ruLyMWe3eDE=";
npmDepsHash = "sha256-pcw+b+IFUG6w07sJ/UN0cPZfvL3oBrSqQBiVhMGquDU=";
doCheck = true;

998
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -40,7 +40,6 @@
"remark-parse": "^10.0.1",
"remark-rehype": "^10.1.0",
"sass": "^1.62.0",
"stringify-entities": "^4.0.3",
"timeago.js": "^4.0.2",
"unified": "^10.1.2",
"unist-util-visit": "^4.1.2",

View File

@ -1,42 +1,6 @@
import { stringifyEntities } from 'stringify-entities';
import * as fs from 'fs/promises';
import config from '$lib/config';
/**
* @param {Record<string, any>} properties
*/
function renderProperties(properties) {
if (Object.keys(properties).length === 0) return '';
return ' ' + Object.entries(properties)
.filter(([k, v]) => k !== '' && v !== '')
.map(([k, v]) =>
v ? `${k}=${typeof v === 'string' ? `"${stringifyEntities(v)}"` : v.toString()}` : k
).join(' ');
}
/**
* @param {ASTMap} ast
* @returns {string}
*/
// todo: obliterate from orbit
export function renderASTMap(ast) {
switch (ast.type) {
case 'root':
return ast.children.map(c => renderASTMap(c)).join('')
case 'element':
if (ast.tagName === 'a') {
ast.properties.target = '_blank';
ast.properties.rel = 'noreferrer noopener';
}
if (ast.properties.id && ast.properties.id.includes('cohost-blogger-ignore')) return '';
return `<${ast.tagName}${renderProperties(ast.properties)}>${ast.children.map(c => renderASTMap(c)).join('')}</${ast.tagName}>`;
case 'text':
return stringifyEntities(ast.value);
default:
return '';
}
}
const COHOST_API_URI = 'https://cohost.org/api/v1/trpc/';
/**
* @param {string} route

View File

@ -1,6 +1,6 @@
<script>
import Comment from '$lib/Comment.svelte';
import { getPostImages, getPostPublishDate, getPostSlug, renderASTMap } from '$lib/cohost';
import { getPostImages, getPostPublishDate, getPostSlug } from '$lib/cohost';
import { renderPostMarkdown, renderPostSummaryPlaintext } from '$lib/markdown/rendering';
import { formatDate } from '$lib/utils';
import * as timeago from 'timeago.js';