mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-11-21 13:28:23 +00:00
Update Download endpoint to export four shapes of Markdown files
Restructures PDF download into an Export menu containing the PDF export and 4 Markdown Options Slightly tweaks tests Effectively moves the api.mergeBrewText to helpers. I think this makes more sense. Changes the download extension from txt to 'md`. The Commonmark, TOML, and JSON exports are the same with the frontmatter in a slightly different shape. These were selected based on lightweight research into Markdown Frontmatter. If specific formats - such as Obsidian - are different enough in terms of formatting the frontmatter or desired metadata content, this is fairly easy
This commit is contained in:
+13
-3
@@ -15,7 +15,7 @@ import fs from 'fs';
|
||||
import dbCheck from './middleware/dbCheck.js';
|
||||
import sanitizeFilename from 'sanitize-filename';
|
||||
import { DEFAULT_BREW } from './brewDefaults.js';
|
||||
import { splitTextStyleAndMetadata } from '../shared/helpers.js';
|
||||
import { splitTextStyleAndMetadata, transformFrontmatter } from '../shared/helpers.js';
|
||||
import GoogleActions from './googleActions.js';
|
||||
|
||||
import api from './homebrew.api.js';
|
||||
@@ -135,9 +135,19 @@ export default function pageRoutes({
|
||||
});
|
||||
|
||||
//Download brew source page
|
||||
app.get('/download/:id', asyncHandler(getBrew('share')), (req, res)=>{
|
||||
app.get('/download/:format/:id', asyncHandler(getBrew('share')), async (req, res)=>{
|
||||
const markdownFormats = {
|
||||
hb : 'homebrewery',
|
||||
cm : 'commonmark',
|
||||
toml : 'toml',
|
||||
json : 'json'
|
||||
};
|
||||
|
||||
const { brew } = req;
|
||||
|
||||
const lastBrew = brew.text;
|
||||
sanitizeBrew(brew, 'share');
|
||||
brew.text = await transformFrontmatter(brew, req.params.format);
|
||||
const prefix = 'HB - ';
|
||||
|
||||
const encodeRFC3986ValueChars = (str)=>{
|
||||
@@ -152,7 +162,7 @@ export default function pageRoutes({
|
||||
res.set({
|
||||
'Cache-Control' : 'no-cache',
|
||||
'Content-Type' : 'text/plain',
|
||||
'Content-Disposition' : `attachment; filename*=UTF-8''${encodeRFC3986ValueChars(fileName)}.txt`
|
||||
'Content-Disposition' : `attachment; filename*=UTF-8''${encodeRFC3986ValueChars(fileName)}.${markdownFormats[req.params.format]}.md`
|
||||
});
|
||||
res.status(200).send(brew.text);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user