blog-engine-sac
Advanced tools
Comparing version 1.0.8 to 1.1.0
@@ -62,3 +62,2 @@ export { createCategoryHtml }; | ||
<div class="col-lg-8 col-md-10 mx-auto"> | ||
<ol> | ||
@@ -65,0 +64,0 @@ ${listOfPosts} |
@@ -7,6 +7,6 @@ export { createIndexHtml }; | ||
import { normalizeDate } from "../source/dates.js"; | ||
import {linkFromCategory, linkFromPost, makeUrl, escapeHtml} from "./links.js"; | ||
const createIndexHtml = (options) => { | ||
const { body, title, author, description, posts } = options; | ||
const { body, title, author, description, posts, categories } = options; | ||
const MAX_ARTICLE_PREVIEW = Number.MAX_SAFE_INTEGER || 3; | ||
@@ -20,6 +20,5 @@ // can make this number smaller once a ui element has been created to display all entries | ||
}).map(function (post) { | ||
const link = `b/${escape(post.title)}.html`; | ||
return `<a href="${link}" class="post-preview"> | ||
return `<a href="${makeUrl(post.title)}" class="post-preview"> | ||
<span class="post-title"> | ||
${post.title} | ||
${escapeHtml(post.title)} | ||
</span> | ||
@@ -39,4 +38,4 @@ <p class="post-meta">Posted by | ||
const categoriesLinks = Object.entries(options.categories).map(function ([categoryName, posts]) { | ||
return `<li><a href="./c/${categoryName}.html">${categoryName}</a></li>`; | ||
const categoriesLinks = Object.entries(categories).map(function ([categoryName, posts]) { | ||
return `<li>${linkFromCategory(categoryName)}</li>`; | ||
}).join(``); | ||
@@ -43,0 +42,0 @@ return `<!DOCTYPE html> |
@@ -5,3 +5,3 @@ export {createPostHtml}; | ||
import { createHeaderHtml } from "./header.html.js"; | ||
import { normalizeDate } from "../source/dates.js"; | ||
import { linkFromPost, linkFromCategory } from "./links.js"; | ||
@@ -59,3 +59,3 @@ | ||
</div> | ||
<hr> | ||
<div class="row"> | ||
@@ -66,3 +66,3 @@ <div class="col-lg-8 col-md-10 mx-auto"> | ||
options.finalTags.map(function (tag) { | ||
return `<li>${tag}</li>`; | ||
return `<li>${linkFromCategory(tag)}</li>`; | ||
}).join(``) | ||
@@ -80,8 +80,3 @@ }</ul> | ||
`; | ||
}; | ||
// duplicate from search | ||
const makeUrl = (ref) => { | ||
return `/b/${ref}`; | ||
}; | ||
@@ -93,13 +88,8 @@ const nextInteractionHtml = (post) => { | ||
if (next) { | ||
nextHtml = `Next ${linkFromName(next)}`; | ||
nextHtml = `Next ${linkFromPost(next)}`; | ||
} | ||
if (previous) { | ||
previousHtml = `Previous ${linkFromName(previous)}`; | ||
previousHtml = `Previous ${linkFromPost(previous)}`; | ||
} | ||
return `<p class="col-lg-8 col-md-10 mx-auto">${nextHtml} ${previousHtml}</p>`; | ||
}; | ||
const linkFromName = (post) => { | ||
const {title} = post; | ||
return `<a href="${makeUrl(title)}">${title}</a>`; | ||
}; |
{ | ||
"name": "blog-engine-sac", | ||
"version": "1.0.8", | ||
"version": "1.1.0", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "bin": { |
@@ -36,7 +36,7 @@ # Blog | ||
categories are provided by the user as an array for each post | ||
categories are provided by the user as an array for the entire blog | ||
for example: travel, cuisine, sports | ||
Each category will have a dedicated index page that acts like the main index page but only lists post of that category | ||
Each category will have a dedicated index page that acts like the main index page but only lists post of that category. Posts will be in that category if they have a corresponding tag. | ||
@@ -43,0 +43,0 @@ ### Edit Images |
@@ -134,2 +134,3 @@ export { processPost, supportedFormats, getDetailsFromPost }; | ||
const meta = { | ||
indexed: true, | ||
hasExternalMeta: false, | ||
@@ -190,4 +191,3 @@ externalMeta: ``, | ||
console.log(`\t* ${fullPath}`); | ||
return { title, extension, base: parsedPath.base, fullPath }; | ||
}; |
@@ -28,2 +28,3 @@ /* stats.birthtime, can be later than modified date | ||
const footerSource = `${postsPath}/extras/footer.md`; | ||
const categoriesSource = `${postsPath}/extras/categories.json`; | ||
@@ -45,11 +46,14 @@ // output | ||
const createCategories = function (posts) { | ||
const createCategoryMap = function (posts, categoriesList) { | ||
/*[{ | ||
"tag": "travel", | ||
"name": "Travel"}] */ | ||
const categories = {}; | ||
categoriesList.forEach(({tag, name}) => { | ||
categories[tag] = []; | ||
}); | ||
posts.forEach(function (post) { | ||
post.categories.forEach(function (category) { | ||
if (!Object.prototype.hasOwnProperty.call(categories, category)) { | ||
categories[category] = [post]; | ||
} else { | ||
categories[category].push(post); | ||
post.finalTags.forEach(function (tag) { | ||
if (Object.prototype.hasOwnProperty.call(categories, tag)) { | ||
categories[tag].push(post); | ||
} | ||
@@ -61,5 +65,26 @@ }); | ||
const createCategoryPages = function (categories, commonOptions) { | ||
const createHiddenCategoryMap = function (posts, categoryMap, categoriesList) { | ||
/*[{ | ||
"tag": "travel", | ||
"name": "Travel"}] */ | ||
const hiddenCategoryMap = {}; | ||
posts.forEach(function (post) { | ||
post.finalTags.forEach(function (tag) { | ||
if (Object.prototype.hasOwnProperty.call(categoryMap, tag)) { | ||
return; | ||
} | ||
if (!Object.prototype.hasOwnProperty.call(hiddenCategoryMap, tag)) { | ||
hiddenCategoryMap[tag] = []; | ||
} | ||
hiddenCategoryMap[tag].push(post); | ||
}); | ||
}) | ||
return hiddenCategoryMap; | ||
}; | ||
const createCategoryPages = function (categoriesMap, hiddenCategoryMap, commonOptions) { | ||
const allCategories = Object.assign({}, categoriesMap, hiddenCategoryMap); | ||
return Promise.all( | ||
Object.entries(categories).map(function ([categoryName, posts]) { | ||
Object.entries(allCategories).map(function ([categoryName, posts]) { | ||
const categoryHTML = createCategoryHtml(Object.assign({ | ||
@@ -113,2 +138,7 @@ categoryName, | ||
const getCategoriesList = async () => { | ||
const listJson = await textFileContent(categoriesSource); | ||
return JSON.parse(listJson); | ||
}; | ||
const buildSite = async () => { | ||
@@ -119,2 +149,3 @@ // independent | ||
}); | ||
const categoriesPromise = getCategoriesList(); | ||
const commonOptions = { | ||
@@ -146,5 +177,8 @@ author, | ||
posts.forEach(function (post, i) { | ||
post.previous = posts[i - 1]; | ||
post.next = posts[i + 1]; | ||
post.next = posts[i - 1]; | ||
post.previous = posts[i + 1]; | ||
}); | ||
posts.forEach(function (post, i) { | ||
console.log(`\t** ${post.title}`) | ||
}); | ||
const allWords = wordCount(posts); | ||
@@ -161,5 +195,7 @@ generateTags(posts, allWords); | ||
const aboutPromise = createAbout(commonOptions); | ||
const categories = createCategories(posts, commonOptions); | ||
createCategoryPages(categories); | ||
const indexPromise = createIndex(posts, categories, commonOptions); | ||
const categories = await categoriesPromise; | ||
const categoryMap = createCategoryMap(posts, categories, commonOptions); | ||
const hiddenCategoryMap = createHiddenCategoryMap(posts, categories, categoryMap, commonOptions); | ||
createCategoryPages(categoryMap, hiddenCategoryMap, commonOptions); | ||
const indexPromise = createIndex(posts, categoryMap, commonOptions); | ||
createPosts(posts, commonOptions); | ||
@@ -166,0 +202,0 @@ |
101951
25
2221