as promised, obliterate renderASTMap from orbit
This commit is contained in:
parent
56bf08de16
commit
2f7d5e0930
|
@ -18,7 +18,7 @@
|
|||
pname = "cohost-blogger";
|
||||
inherit (package) version;
|
||||
|
||||
npmDepsHash = "sha256-VSEkIBeF3FSYI8FbvgskznPmlqavM6g4ruLyMWe3eDE=";
|
||||
npmDepsHash = "sha256-pcw+b+IFUG6w07sJ/UN0cPZfvL3oBrSqQBiVhMGquDU=";
|
||||
|
||||
doCheck = true;
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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';
|
||||
|
|
Loading…
Reference in New Issue