UNPKG

@rr0/cms

Version:

RR0 Content Management System (CMS)

34 lines (33 loc) 1.38 kB
import { SsiEchoVarReplaceCommand } from "ssg-api"; /** * Replaces "<!--#echo var="author" -->" and "<!--#echo var="copyright" -->" * by the page's <meta name="author">s' content. */ export class AuthorReplaceCommand extends SsiEchoVarReplaceCommand { constructor(timeRenderer) { super("author"); this.timeRenderer = timeRenderer; } async createReplacer(context) { return { replace: (_match, ..._args) => { const file = context.file; let authors = file.meta.author; let authorsHtml = authors.map(author => `<span class="people">${author}</span>`).join(" & "); const copyright = file.meta.copyright; if (copyright) { authorsHtml += authorsHtml ? ": " + copyright : copyright; } if (authorsHtml && context.time.getYear()) { const { result, replacement } = this.timeRenderer.renderContent(context, undefined, { url: true, contentOnly: false }); result.append(replacement); authorsHtml += ", " + result.outerHTML; } if (authorsHtml) { authorsHtml = `<div class="document-author">${authorsHtml}</div>`; } return authorsHtml; } }; } }