Skip to content

Commit ece81df

Browse files
committed
Replace Markdown renderer
1 parent 89ac7f1 commit ece81df

File tree

10 files changed

+35
-29
lines changed

10 files changed

+35
-29
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ This sample currently assumes you've performed the following provisioning action
3232
- [ ] Azure Template for automated deployment
3333
- [ ] List of blog posts (ordered list of everything under `/blog`)
3434
- [ ] Add auxiliary storage table for metadata lookup
35+
- [ ] Set blob metadata from page frontmatter
3536
- [ ] Flesh out example content and formatting tests
3637
- [x] Reformat asset links (images, stylesheets, etc.)
3738
- [x] Split blob storage access from rendering (`renderTemplateActivity`)

copyActivity/index.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
* triggered by an orchestrator function.
44
*/
55

6-
const fs = require("fs"),
7-
path = require("path"),
8-
storage = require("azure-storage"),
9-
marked = require('marked'),
10-
mime = require('mime-types'),
6+
const storage = require("azure-storage"),
117
blobService = storage.createBlobService(process.env['AzureWebJobsStorage']);
128

139

@@ -24,7 +20,7 @@ const copyBlob = async (srcUri, pathname) => {
2420
}
2521

2622
module.exports = async function (context, name) {
27-
context.log("copy:", name);
23+
//context.log("copy:", name);
2824
const srcUri = blobService.getUrl('raw-markup', name),
2925
result = await copyBlob(srcUri, name);
3026

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"durable-functions": "^1.2.2",
88
"cheerio": "^1.0.0-rc.3",
99
"gray-matter": "^4.0.2",
10-
"marked": "^0.7.0",
10+
"remarkable": "^2.0.0",
1111
"moment": "^2.24.0",
1212
"mustache": "^3.0.1",
1313
"textile-js": "^2.0.4",

renderMarkdownActivity/index.js

+20-13
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,26 @@
55

66
const storage = require("azure-storage"),
77
matter = require("gray-matter"),
8-
marked = require('marked'),
8+
remarkable = require('remarkable'),
9+
hljs = require('highlight.js'),
910
blobService = storage.createBlobService(process.env['AzureWebJobsStorage']);
1011

11-
marked.setOptions({
12-
renderer: new marked.Renderer(),
13-
highlight: function(code) {
14-
return require('highlight.js').highlightAuto(code).value;
15-
},
16-
gfm: true,
17-
breaks: false,
18-
smartLists: true,
19-
smartypants: true,
20-
xhtml: false
12+
var md = new remarkable.Remarkable({
13+
highlight: function (str, lang) {
14+
if (lang && hljs.getLanguage(lang)) {
15+
try {
16+
return hljs.highlight(lang, str).value;
17+
} catch (err) {}
18+
}
19+
20+
try {
21+
return hljs.highlightAuto(str).value;
22+
} catch (err) {}
23+
24+
return ''; // use external default escaping
25+
},
26+
typographer: true,
27+
html: true
2128
});
2229

2330
const getMarkup = async (blobName) => {
@@ -33,11 +40,11 @@ const getMarkup = async (blobName) => {
3340
};
3441

3542
module.exports = async function (context, name) {
36-
context.log(name);
43+
//context.log(name);
3744
const response = await getMarkup(name),
3845
page = matter(response);
3946
page.name = name;
4047
// replace Markdown with rendered HTML
41-
page.content = marked(page.content);
48+
page.content = md.render(page.content);
4249
return page;
4350
};

renderPipeline/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ const df = require('durable-functions'),
1414
extensions: ['.text', '.textile'],
1515
pipeline: ['renderTextileActivity', 'renderTemplateActivity']
1616
},
17+
/* Render HTML snippets directly (disabled to allow custom content pass-through)
1718
renderTemplateActivity: {
1819
extensions: ['.htm', '.html'],
1920
pipeline: ['renderTemplateActivity']
2021
}
22+
*/
2123
};
2224

2325
module.exports = df.orchestrator(function* (context) {
@@ -40,7 +42,7 @@ module.exports = df.orchestrator(function* (context) {
4042
for(let activity of pipeline) {
4143
// context.log("running:", activity);
4244
currentItem = yield context.df.callActivity(activity, currentItem);
43-
context.log(currentItem);
45+
//context.log(currentItem);
4446
if(currentItem == null) { // the activity has failed
4547
context.log("error:", activity)
4648
yield cancel(activity)

renderTemplateActivity/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Object.fromEntries = arr => Object.assign({}, ...Array.from(arr, ([k, v]) => ({[
4545

4646

4747
module.exports = async function (context, page) {
48-
context.log(page.name);
48+
// context.log(page.name);
4949

5050
const template = await getTemplate('_assets/page_template.html');
5151

@@ -96,7 +96,7 @@ module.exports = async function (context, page) {
9696

9797
const result = await uploadHTML(page.name.substr(0, page.name.lastIndexOf(".")) + ".html", html);
9898

99-
context.log(html);
100-
context.log(result);
99+
// context.log(html);
100+
// context.log(result);
101101
return result;
102102
};

renderTextileActivity/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ const getMarkup = async (blobName) => {
2121
};
2222

2323
module.exports = async function (context, name) {
24-
context.log(name);
24+
// context.log(name);
25+
2526
const response = await getMarkup(name),
2627
page = matter(response);
2728
page.name = name;
28-
// replace Markdown with rendered HTML
29+
30+
// replace Textile with rendered HTML
2931
page.content = textile(page.content);
3032
return page;
3133
};

sampleContent/404.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
---
22
Title: Page Not Found
3-
---
4-
5-
Page not found.
3+
---
-43.6 KB
Loading
-1.03 KB
Binary file not shown.

0 commit comments

Comments
 (0)