MarkMark - add sha256 hashing (+update HTML renderer to insert IDs), update MD renderer to include dates, add syndication for bookmarks
This commit is contained in:
@@ -29,7 +29,7 @@ export class HtmlRenderer {
|
||||
linkTitle += ` <span class="markmark link-tags">${link.tags.map(x => '<span class="markmark link-tag">#' + x + '</span>').join(' ')}</span>`
|
||||
}
|
||||
|
||||
mmLines.push(`<li class="markmark link-title">${marked.marked.parse(linkTitle)}<ul class="markmark url-list">`)
|
||||
mmLines.push(`<li class="markmark link-title" id="link-${link.hash}">${marked.marked.parse(linkTitle)}<ul class="markmark url-list">`)
|
||||
|
||||
for ( const url of link.urls ) {
|
||||
mmLines.push(`<li class="markmark link-url"><a href="${url}" target="_blank">${url}</a></li>`)
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import {isNamedSection, MarkMark} from './types'
|
||||
|
||||
export class MarkMarkRenderer {
|
||||
public render(mm: MarkMark): string {
|
||||
public render(mm: MarkMark, frontmatter: boolean = true): string {
|
||||
let mmLines: string[] = ['\n']
|
||||
|
||||
// Write the frontmatter
|
||||
mmLines.push(`[//]: #(markmark-syntax: ${mm.frontmatter.syntax})`)
|
||||
if ( mm.frontmatter.authorName ) mmLines.push(`[//]: #(markmark-author-name: ${mm.frontmatter.authorName})`)
|
||||
if ( mm.frontmatter.authorEmail ) mmLines.push(`[//]: #(markmark-author-email: ${mm.frontmatter.authorEmail})`)
|
||||
if ( mm.frontmatter.authorHref ) mmLines.push(`[//]: #(markmark-author-href: ${mm.frontmatter.authorHref})`)
|
||||
if ( frontmatter ) {
|
||||
mmLines.push(`[//]: #(markmark-syntax: ${mm.frontmatter.syntax})`)
|
||||
if (mm.frontmatter.authorName) mmLines.push(`[//]: #(markmark-author-name: ${mm.frontmatter.authorName})`)
|
||||
if (mm.frontmatter.authorEmail) mmLines.push(`[//]: #(markmark-author-email: ${mm.frontmatter.authorEmail})`)
|
||||
if (mm.frontmatter.authorHref) mmLines.push(`[//]: #(markmark-author-href: ${mm.frontmatter.authorHref})`)
|
||||
}
|
||||
|
||||
for ( const section of mm.sections ) {
|
||||
mmLines.push('\n')
|
||||
@@ -23,6 +25,11 @@ export class MarkMarkRenderer {
|
||||
|
||||
for ( const link of section.links ) {
|
||||
let linkTitle = `- ${link.title}`
|
||||
|
||||
if ( link.date ) {
|
||||
linkTitle += ` (${this.formatDate(link.date)})`
|
||||
}
|
||||
|
||||
if ( link.tags.length ) {
|
||||
linkTitle += ` ${link.tags.map(x => '#' + x).join(' ')}`
|
||||
}
|
||||
@@ -37,4 +44,11 @@ export class MarkMarkRenderer {
|
||||
|
||||
return mmLines.join('\n')
|
||||
}
|
||||
|
||||
private formatDate(date: Date): string {
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0'); // Months are zero-based
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
return `${year}-${month}-${day}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as marked from 'marked'
|
||||
import {FrontMatter, isNamedSection, Link, MarkMark, Section} from './types'
|
||||
import * as crypto from 'crypto'
|
||||
|
||||
export class Parser {
|
||||
public parse(content: string): MarkMark {
|
||||
@@ -65,6 +66,7 @@ export class Parser {
|
||||
currentLink = {
|
||||
title,
|
||||
date,
|
||||
hash: crypto.createHash('sha256').update(token.text).digest('hex'),
|
||||
tags: this.parseTags(token.text),
|
||||
urls: [],
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ export const isNamedSection = (what: Section): what is NamedSection =>
|
||||
hasOwnProperty(what, 'title') && (typeof what.title === 'string')
|
||||
|
||||
export type Link = {
|
||||
hash: string,
|
||||
title: string,
|
||||
date?: Date,
|
||||
tags: string[],
|
||||
|
||||
Reference in New Issue
Block a user