|
1 |
| -const helpers = require( './helpers' ); |
| 1 | +const helpers = require("./helpers"); |
2 | 2 |
|
3 |
| -function blog_table( posts, style ) { |
4 |
| - let column = style.split( '-' ); |
5 |
| - column = ( typeof column[ 2 ] !== 'undefined' ) ? column[ 2 ] : 2; |
| 3 | +function blog_table(posts, style) { |
| 4 | + let column = style.split("-"); |
| 5 | + column = typeof column[2] !== "undefined" ? column[2] : 2; |
6 | 6 |
|
7 |
| - let html = '<table><tr>'; |
| 7 | + let html = "<table><tr>"; |
8 | 8 |
|
9 |
| - posts.forEach( ( post, index ) => { |
10 |
| - const {url, title, brief, coverImage, dateUpdated, dateAdded} = post; |
| 9 | + posts.forEach((post, index) => { |
| 10 | + const { url, title, brief, coverImage, dateUpdated, dateAdded } = post; |
11 | 11 |
|
12 |
| - if( 0 !== index && ( index % column ) === 0 ) { |
13 |
| - html += '</tr><tr>'; |
| 12 | + if (0 !== index && index % column === 0) { |
| 13 | + html += "</tr><tr>"; |
14 | 14 | }
|
15 | 15 |
|
16 |
| - html += `<td>${helpers.img( coverImage, url, title, '', '' )} |
17 |
| -${helpers.a( url, title, `<strong>${title}</strong>` )} |
18 |
| -<div><strong>${helpers.parseDate(dateAdded)}</strong> | <strong>${helpers.parseDate(dateUpdated)}</strong></div> |
| 16 | + html += `<td>${helpers.img(coverImage, url, title, "", "")} |
| 17 | +${helpers.a(url, title, `<strong>${title}</strong>`)} |
| 18 | +<div><strong>${helpers.parseDate(dateAdded)}</strong>${ |
| 19 | + dateUpdated === null |
| 20 | + ? "" |
| 21 | + : ` | <strong>Updated: ${helpers.parseDate( |
| 22 | + dateUpdated |
| 23 | + )}</strong>` |
| 24 | + }</div> |
19 | 25 | <br/> ${brief}</td>`;
|
20 |
| - } ); |
| 26 | + }); |
21 | 27 |
|
22 |
| - return html += '</tr></table>'; |
| 28 | + return (html += "</tr></table>"); |
23 | 29 | }
|
24 | 30 |
|
25 |
| -async function lists( posts, STYLE ) { |
| 31 | +async function lists(posts, STYLE) { |
26 | 32 | let markdown = [];
|
27 |
| - STYLE = STYLE.toLowerCase(); |
28 |
| - posts.forEach( ( post, index ) => { |
29 |
| - switch( STYLE ) { |
30 |
| - case 'list': |
31 |
| - case 'list-unordered': |
32 |
| - markdown.push( `- [${post.title}](${post.url})` ); |
| 33 | + STYLE = STYLE.toLowerCase(); |
| 34 | + posts.forEach((post, index) => { |
| 35 | + switch (STYLE) { |
| 36 | + case "list": |
| 37 | + case "list-unordered": |
| 38 | + markdown.push(`- [${post.title}](${post.url})`); |
33 | 39 | break;
|
34 |
| - case 'list-ordered': |
35 |
| - markdown.push( `1. [${post.title}](${post.url})` ); |
| 40 | + case "list-ordered": |
| 41 | + markdown.push(`1. [${post.title}](${post.url})`); |
36 | 42 | break;
|
37 |
| - case 'list-gist': |
38 |
| - markdown.push( `${index + 1}. ${post.title}` ); |
| 43 | + case "list-gist": |
| 44 | + markdown.push(`${index + 1}. ${post.title}`); |
39 | 45 | break;
|
40 | 46 | }
|
41 |
| - |
42 |
| - } ); |
43 |
| - return markdown.join( '\n' ); |
| 47 | + }); |
| 48 | + return markdown.join("\n"); |
44 | 49 | }
|
45 | 50 |
|
46 |
| -async function blog( posts, STYLE ) { |
47 |
| - let markdown = []; |
48 |
| - STYLE = STYLE.toLowerCase(); |
49 |
| - let isalternate = ( 'blog-alternate' === STYLE ); |
50 |
| - STYLE = ( 'blog-alternate' === STYLE ) ? 'blog-left' : STYLE; |
| 51 | +async function blog(posts, STYLE) { |
| 52 | + let markdown = []; |
| 53 | + STYLE = STYLE.toLowerCase(); |
| 54 | + let isalternate = "blog-alternate" === STYLE; |
| 55 | + STYLE = "blog-alternate" === STYLE ? "blog-left" : STYLE; |
51 | 56 |
|
52 |
| - if( STYLE.startsWith( 'blog-grid' ) ) { |
53 |
| - return blog_table( posts, STYLE ); |
| 57 | + if (STYLE.startsWith("blog-grid")) { |
| 58 | + return blog_table(posts, STYLE); |
54 | 59 | }
|
55 | 60 |
|
56 |
| - posts.forEach( post => { |
57 |
| - const {url, title, brief, coverImage, dateUpdated, dateAdded} = post; |
| 61 | + posts.forEach((post) => { |
| 62 | + const { url, title, brief, coverImage, dateUpdated, dateAdded } = post; |
58 | 63 |
|
59 |
| - switch( STYLE ) { |
60 |
| - case 'blog': |
61 |
| - markdown.push( `<h3>${helpers.a( url, title, title )}</h3> |
62 |
| -${helpers.img( coverImage, url, title, '', '400px' )} |
63 |
| -<div><strong>${helpers.parseDate(dateAdded)}</strong> | <strong>${helpers.parseDate(dateUpdated)}</strong></div> |
64 |
| -<p>${brief}</p>` ); |
| 64 | + switch (STYLE) { |
| 65 | + case "blog": |
| 66 | + markdown.push(`<h3>${helpers.a(url, title, title)}</h3> |
| 67 | +${helpers.img(coverImage, url, title, "", "400px")} |
| 68 | +<div><strong>${helpers.parseDate(dateAdded)}</strong>${ |
| 69 | + dateUpdated === null |
| 70 | + ? "" |
| 71 | + : ` | <strong>Updated: ${helpers.parseDate( |
| 72 | + dateUpdated |
| 73 | + )}</strong>` |
| 74 | + }</div> |
| 75 | +<p>${brief}</p>`); |
65 | 76 | break;
|
66 |
| - case 'blog-left': |
67 |
| - case 'blog-right': |
68 |
| - let align = ( 'blog-left' === STYLE ) ? 'left' : 'right'; |
69 |
| - markdown.push( `<p align="left"> |
70 |
| -${helpers.img( coverImage, url, title, align, '250px' )} |
71 |
| -${helpers.a( url, title, `<strong>${title}</strong>` )} |
72 |
| -<div><strong>${helpers.parseDate(dateAdded)}</strong> | <strong>${helpers.parseDate(dateUpdated)}</strong></div> |
73 |
| -<br/> ${brief} </p> <br/> <br/>` ); |
74 |
| - if( isalternate ) { |
75 |
| - STYLE = ( 'blog-left' === STYLE ) ? 'blog-right' : 'blog-left'; |
| 77 | + case "blog-left": |
| 78 | + case "blog-right": |
| 79 | + let align = "blog-left" === STYLE ? "left" : "right"; |
| 80 | + markdown.push(`<p align="left"> |
| 81 | +${helpers.img(coverImage, url, title, align, "250px")} |
| 82 | +${helpers.a(url, title, `<strong>${title}</strong>`)} |
| 83 | +<div><strong>${helpers.parseDate(dateAdded)}</strong>${ |
| 84 | + dateUpdated === null |
| 85 | + ? "" |
| 86 | + : ` | <strong>Updated: ${helpers.parseDate( |
| 87 | + dateUpdated |
| 88 | + )}</strong>` |
| 89 | + }</div> |
| 90 | +<br/> ${brief} </p> <br/> <br/>`); |
| 91 | + if (isalternate) { |
| 92 | + STYLE = "blog-left" === STYLE ? "blog-right" : "blog-left"; |
76 | 93 | }
|
77 | 94 | break;
|
78 | 95 | }
|
79 |
| - |
80 |
| - } ); |
81 |
| - return markdown.join( `\n` ); |
| 96 | + }); |
| 97 | + return markdown.join(`\n`); |
82 | 98 | }
|
83 | 99 |
|
84 | 100 | module.exports = {
|
85 | 101 | list: lists,
|
86 |
| - blog: blog |
| 102 | + blog: blog, |
87 | 103 | };
|
0 commit comments