blazed-past-us 0.4.5 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/blazed-past-us-0.5.5.tgz +0 -0
- package/dist/cli/build.js +1 -1
- package/dist/engine/getters.d.ts +3 -8
- package/dist/engine/getters.js +3 -30
- package/dist/engine/render.d.ts +2 -2
- package/dist/engine/render.js +5 -4
- package/dist/engine/requests.d.ts +5 -0
- package/dist/engine/requests.js +43 -0
- package/dist/engine/utils.d.ts +6 -6
- package/dist/engine/utils.js +21 -14
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/server/file-builder.d.ts +2 -2
- package/dist/server/parse-markdown.js +1 -1
- package/dist/template/index.html +1 -2
- package/dist/template/src/config.json +1 -2
- package/dist/template/src/main.js +5 -9
- package/dist/template/src/router.js +10 -8
- package/dist/template/src/styles/header.css +2 -0
- package/dist/template/src/views/home.js +2 -3
- package/dist/template/src/views/post.js +5 -6
- package/package.json +1 -1
- package/blazed-past-us-0.4.5.tgz +0 -0
- /package/dist/template/src/{moonlight-li.json → code-block-theme.json} +0 -0
|
Binary file
|
package/dist/cli/build.js
CHANGED
|
@@ -4,7 +4,7 @@ import fs from 'node:fs';
|
|
|
4
4
|
import fsPromises from 'node:fs/promises';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { log } from '../engine/utils.js';
|
|
7
|
-
import { generatePostMetadata, writeTransformedPostFile } from '../server/file-builder.js';
|
|
7
|
+
import { generatePostMetadata, writeTransformedPostFile, } from '../server/file-builder.js';
|
|
8
8
|
/**
|
|
9
9
|
* CLI entry point.
|
|
10
10
|
* Resolves project paths and builds bundle.
|
package/dist/engine/getters.d.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
declare function getPostData(
|
|
3
|
-
declare function getAllPostsHTML(postsMetaData: PostMetaData[], baseURL: string): Promise<{
|
|
4
|
-
slug: string;
|
|
5
|
-
html: string | void;
|
|
6
|
-
}[]>;
|
|
7
|
-
declare function getPostsMetaData(baseURL: string, config: Config): Promise<PostMetaData[]>;
|
|
1
|
+
import type { PostMetadata, Config, PostDataType } from '../types';
|
|
2
|
+
declare function getPostData(postsMetadata: PostMetadata[], slug: string, option: PostDataType): string | string[] | Date | undefined;
|
|
8
3
|
declare function getSlug(htmlFilename: string): string;
|
|
9
4
|
declare function getTitle(htmlFilename: string): string;
|
|
10
5
|
declare function getBrief(fileContent: string, lines: number): string;
|
|
11
6
|
declare function getTags(fileContent: string): string[];
|
|
12
7
|
declare function getColoredTagsHTML(tags: string, config: Config): string;
|
|
13
|
-
export { getPostData,
|
|
8
|
+
export { getPostData, getTitle, getTags, getBrief, getColoredTagsHTML, getSlug };
|
package/dist/engine/getters.js
CHANGED
|
@@ -1,32 +1,5 @@
|
|
|
1
|
-
function getPostData(
|
|
2
|
-
return
|
|
3
|
-
}
|
|
4
|
-
async function getAllPostsHTML(postsMetaData, baseURL) {
|
|
5
|
-
const allPostsFilename = postsMetaData.map((el) => ({ slug: el.slug, filename: el.filename }));
|
|
6
|
-
const allPostsHTML = [];
|
|
7
|
-
for (const post of allPostsFilename) {
|
|
8
|
-
const HTML = await fetch(`${baseURL}posts/${post.filename}`)
|
|
9
|
-
.then((resp) => resp.text())
|
|
10
|
-
.catch((error) => console.error(error));
|
|
11
|
-
allPostsHTML.push({ slug: post.slug, html: HTML });
|
|
12
|
-
}
|
|
13
|
-
return allPostsHTML;
|
|
14
|
-
}
|
|
15
|
-
async function getPostsMetaData(baseURL, config) {
|
|
16
|
-
const postsRelativeDataPath = config.posts_data_path;
|
|
17
|
-
const postsPath = [baseURL, postsRelativeDataPath].join('');
|
|
18
|
-
try {
|
|
19
|
-
const resp = await fetch(postsPath);
|
|
20
|
-
if (!resp.ok) {
|
|
21
|
-
throw new Error(`HTTP error! Status: ${resp.status}`);
|
|
22
|
-
}
|
|
23
|
-
const data = await resp.json();
|
|
24
|
-
return data;
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
console.error('Failed to fetch posts metadata:', error);
|
|
28
|
-
throw error;
|
|
29
|
-
}
|
|
1
|
+
function getPostData(postsMetadata, slug, option) {
|
|
2
|
+
return postsMetadata.find((post) => post.slug === slug)?.[option];
|
|
30
3
|
}
|
|
31
4
|
function getSlug(htmlFilename) {
|
|
32
5
|
return htmlFilename.replace('.html', '');
|
|
@@ -69,4 +42,4 @@ function getColoredTagsHTML(tags, config) {
|
|
|
69
42
|
})
|
|
70
43
|
.join(`<span class="tag-separator">, </span>`);
|
|
71
44
|
}
|
|
72
|
-
export { getPostData,
|
|
45
|
+
export { getPostData, getTitle, getTags, getBrief, getColoredTagsHTML, getSlug };
|
package/dist/engine/render.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Views,
|
|
2
|
-
declare function render(view: string, root: HTMLElement, views: Views,
|
|
1
|
+
import { Views, PostMetadata, PostHTML } from '../types.js';
|
|
2
|
+
declare function render(view: string, root: HTMLElement, views: Views, postsMetadata: PostMetadata[], postsHTML?: PostHTML[], postTagsFilter?: string, postSlug?: string): void;
|
|
3
3
|
export { render };
|
package/dist/engine/render.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { postExists, inject } from './utils.js';
|
|
2
|
-
function render(view, root, views,
|
|
2
|
+
function render(view, root, views, postsMetadata, postsHTML, postTagsFilter, postSlug) {
|
|
3
3
|
const r = root;
|
|
4
4
|
const { home, post, notFound } = views;
|
|
5
5
|
switch (view) {
|
|
6
6
|
case 'home':
|
|
7
|
-
inject(r, home(postTagsFilter?.split(',')));
|
|
7
|
+
inject(r, home(postTagsFilter?.split(','), postsMetadata));
|
|
8
8
|
break;
|
|
9
9
|
case 'post':
|
|
10
|
-
if (postSlug && postExists(
|
|
11
|
-
|
|
10
|
+
if (postSlug && postExists(postsMetadata, postSlug)) {
|
|
11
|
+
const htmlContent = postsHTML?.find((p) => p.slug === postSlug)?.html;
|
|
12
|
+
post(postSlug, postsMetadata, htmlContent).then((html) => inject(r, html));
|
|
12
13
|
}
|
|
13
14
|
else {
|
|
14
15
|
inject(r, notFound());
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export async function fetchResources(config) {
|
|
2
|
+
try {
|
|
3
|
+
const postsMetadata = await fetchPostsMetaData(config);
|
|
4
|
+
const postsHTML = await fetchAllPostsHTML(config.base_url, postsMetadata);
|
|
5
|
+
return { postsMetadata, postsHTML };
|
|
6
|
+
}
|
|
7
|
+
catch (error) {
|
|
8
|
+
console.log(`Failed to fetch resources.`);
|
|
9
|
+
console.error(error);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
async function fetchAllPostsHTML(baseURL, postsMetadata) {
|
|
13
|
+
const allPostsFilename = postsMetadata.map((el) => ({
|
|
14
|
+
slug: el.slug,
|
|
15
|
+
filename: el.filename,
|
|
16
|
+
}));
|
|
17
|
+
const allPostsHTML = new Array();
|
|
18
|
+
for (const post of allPostsFilename) {
|
|
19
|
+
const HTML = await fetch(`${baseURL}posts/${post.filename}`)
|
|
20
|
+
.then((resp) => resp.text())
|
|
21
|
+
.catch((error) => console.error(error));
|
|
22
|
+
allPostsHTML.push({ slug: post.slug, html: HTML });
|
|
23
|
+
}
|
|
24
|
+
return allPostsHTML;
|
|
25
|
+
}
|
|
26
|
+
async function fetchPostsMetaData(config) {
|
|
27
|
+
// If config.base_url does not end with "/" append it.
|
|
28
|
+
const baseUrl = config.base_url.endsWith('/') ? config.base_url : config.base_url + '/';
|
|
29
|
+
const postsRelativeDataPath = 'posts/data.json';
|
|
30
|
+
const postsPath = [baseUrl, postsRelativeDataPath].join('');
|
|
31
|
+
try {
|
|
32
|
+
const resp = await fetch(postsPath);
|
|
33
|
+
if (!resp.ok) {
|
|
34
|
+
throw new Error(`HTTP error! Status: ${resp.status}`);
|
|
35
|
+
}
|
|
36
|
+
const data = await resp.json();
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.error('Failed to fetch posts metadata:', error);
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
package/dist/engine/utils.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { MsgColor,
|
|
2
|
-
declare function postExists(
|
|
1
|
+
import { Config, MsgColor, PostMetadata } from '../types';
|
|
2
|
+
declare function postExists(postsMetadata: any[], slug: string): boolean;
|
|
3
3
|
declare function getPathnameFromLocationHash(locationHash: string): string;
|
|
4
4
|
declare function beautifyDate(d: Date | undefined): undefined | string;
|
|
5
5
|
declare function inject(root: HTMLElement, html: string): void;
|
|
6
6
|
declare function log(msg: string, color: MsgColor): void;
|
|
7
|
-
declare function
|
|
8
|
-
declare function
|
|
9
|
-
declare function filterByUrlQueryIfPresent(
|
|
7
|
+
declare function activateBoltRotator(): void;
|
|
8
|
+
declare function setTitleAndSubtitle(packageName: string, config: Config): void;
|
|
9
|
+
declare function filterByUrlQueryIfPresent(postsMetadata: PostMetadata[], tags: string[]): PostMetadata[];
|
|
10
10
|
declare function getLocationHashSpecifics(window: Window): {
|
|
11
11
|
pathname: string;
|
|
12
12
|
queryString: string;
|
|
13
13
|
urlParams: URLSearchParams;
|
|
14
14
|
};
|
|
15
|
-
export { postExists, beautifyDate, inject, log,
|
|
15
|
+
export { postExists, beautifyDate, inject, log, activateBoltRotator, setTitleAndSubtitle, getPathnameFromLocationHash, filterByUrlQueryIfPresent, getLocationHashSpecifics, };
|
package/dist/engine/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import pkg from '../../package.json' with { type: 'json' };
|
|
3
|
-
function postExists(
|
|
4
|
-
return
|
|
3
|
+
function postExists(postsMetadata, slug) {
|
|
4
|
+
return postsMetadata.some((post) => post.slug === slug);
|
|
5
5
|
}
|
|
6
6
|
function getPathnameFromLocationHash(locationHash) {
|
|
7
7
|
return locationHash.split('/').splice(1).join('/');
|
|
@@ -36,20 +36,27 @@ function log(msg, color) {
|
|
|
36
36
|
}
|
|
37
37
|
console.log(`${chalk.blue(pkg.name + ' v' + pkg.version)} ${coloredMsg}`);
|
|
38
38
|
}
|
|
39
|
-
function
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
function activateBoltRotator() {
|
|
40
|
+
const logoElement = document.querySelector('.logo');
|
|
41
|
+
window.onhashchange = () => {
|
|
42
|
+
if (logoElement) {
|
|
43
|
+
logoElement.classList.add('rotate');
|
|
44
|
+
setTimeout(() => logoElement.classList.remove('rotate'), 400);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
44
47
|
}
|
|
45
|
-
function
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
function setTitleAndSubtitle(packageName, config) {
|
|
49
|
+
const titleElement = document.querySelector('.title');
|
|
50
|
+
const subtitleElement = document.querySelector('.subtitle');
|
|
51
|
+
if (titleElement) {
|
|
52
|
+
titleElement.innerHTML = packageName.replaceAll('-', ' ');
|
|
53
|
+
}
|
|
54
|
+
if (subtitleElement) {
|
|
55
|
+
subtitleElement.innerHTML = config.subtitle;
|
|
49
56
|
}
|
|
50
57
|
}
|
|
51
|
-
function filterByUrlQueryIfPresent(
|
|
52
|
-
return
|
|
58
|
+
function filterByUrlQueryIfPresent(postsMetadata, tags) {
|
|
59
|
+
return postsMetadata.filter((post) => tags ? tags.some((tag) => post.tags.includes(tag)) : true);
|
|
53
60
|
}
|
|
54
61
|
function getLocationHashSpecifics(window) {
|
|
55
62
|
const hashRoute = window.location.hash;
|
|
@@ -58,4 +65,4 @@ function getLocationHashSpecifics(window) {
|
|
|
58
65
|
const urlParams = new URLSearchParams(queryString);
|
|
59
66
|
return { pathname, queryString, urlParams };
|
|
60
67
|
}
|
|
61
|
-
export { postExists, beautifyDate, inject, log,
|
|
68
|
+
export { postExists, beautifyDate, inject, log, activateBoltRotator, setTitleAndSubtitle, getPathnameFromLocationHash, filterByUrlQueryIfPresent, getLocationHashSpecifics, };
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PostMetadata } from '../types';
|
|
2
2
|
declare function writeTransformedPostFile(outputPath: string, postHtmlContent: string, filename: string): Promise<void>;
|
|
3
|
-
declare function generatePostMetadata(data: Array<
|
|
3
|
+
declare function generatePostMetadata(data: Array<PostMetadata>, filePath: string, htmlFilename: string, postTags: string[]): Promise<void>;
|
|
4
4
|
export { generatePostMetadata, writeTransformedPostFile };
|
|
@@ -20,7 +20,7 @@ async function parseMarkdown(_path) {
|
|
|
20
20
|
.use(remarkParse)
|
|
21
21
|
.use(remarkRehype)
|
|
22
22
|
.use(rehypePrettyCode, {
|
|
23
|
-
theme: JSON.parse(readFileSync(path.join(root, 'src/
|
|
23
|
+
theme: JSON.parse(readFileSync(path.join(root, 'src/code-block-theme.json'), 'utf-8')),
|
|
24
24
|
keepBackground: false,
|
|
25
25
|
})
|
|
26
26
|
.use(rehypeStringify)
|
package/dist/template/index.html
CHANGED
|
@@ -3,10 +3,10 @@ import * as blazed from 'blazed-past-us';
|
|
|
3
3
|
import initRouter from './router';
|
|
4
4
|
import pkg from '../package.json';
|
|
5
5
|
|
|
6
|
-
const root = document.getElementById(
|
|
7
|
-
const
|
|
6
|
+
const root = document.getElementById('root');
|
|
7
|
+
const { postsMetadata, postsHTML } = await blazed.fetchResources(config);
|
|
8
8
|
|
|
9
|
-
initRouter(root,
|
|
9
|
+
initRouter(root, postsMetadata, postsHTML);
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* ----------------------------
|
|
@@ -15,9 +15,5 @@ initRouter(root, postsMetaData);
|
|
|
15
15
|
* These are demo features included in the starter template.
|
|
16
16
|
* You can safely remove any of them.
|
|
17
17
|
*/
|
|
18
|
-
blazed.
|
|
19
|
-
blazed.
|
|
20
|
-
|
|
21
|
-
const postsHTML = await blazed.getAllPostsHTML(postsMetaData, import.meta.env.BASE_URL);
|
|
22
|
-
|
|
23
|
-
export { root, postsMetaData, postsHTML };
|
|
18
|
+
blazed.setTitleAndSubtitle(pkg.name, config);
|
|
19
|
+
blazed.activateBoltRotator();
|
|
@@ -3,25 +3,27 @@ import home from './views/home';
|
|
|
3
3
|
import post from './views/post';
|
|
4
4
|
import notFound from './views/notFound';
|
|
5
5
|
|
|
6
|
-
export default function initRouter(root,
|
|
7
|
-
routeRenderer(root,
|
|
8
|
-
window.addEventListener('hashchange', () =>
|
|
6
|
+
export default function initRouter(root, postsMetadata, postsHTML) {
|
|
7
|
+
routeRenderer(root, postsMetadata, postsHTML);
|
|
8
|
+
window.addEventListener('hashchange', () =>
|
|
9
|
+
routeRenderer(root, postsMetadata, postsHTML)
|
|
10
|
+
);
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
function routeRenderer(root,
|
|
13
|
+
function routeRenderer(root, postsMetadata, postsHTML) {
|
|
12
14
|
const { pathname, queryString, urlParams } = getLocationHashSpecifics(window);
|
|
13
15
|
const views = { home, post, notFound };
|
|
14
16
|
|
|
15
17
|
switch (true) {
|
|
16
18
|
case pathname === '' || pathname === 'home' || queryString:
|
|
17
|
-
render('home', root, views,
|
|
19
|
+
render('home', root, views, postsMetadata, postsHTML, urlParams.get('tags'));
|
|
18
20
|
break;
|
|
19
21
|
|
|
20
|
-
case postExists(
|
|
21
|
-
render('post', root, views,
|
|
22
|
+
case postExists(postsMetadata, pathname):
|
|
23
|
+
render('post', root, views, postsMetadata, postsHTML, undefined, pathname);
|
|
22
24
|
break;
|
|
23
25
|
|
|
24
26
|
default:
|
|
25
|
-
render('404', root, views,
|
|
27
|
+
render('404', root, views, postsMetadata);
|
|
26
28
|
}
|
|
27
29
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
header {
|
|
2
2
|
display: flex;
|
|
3
3
|
flex-direction: row;
|
|
4
|
+
align-items: center;
|
|
4
5
|
margin: 4.5rem 0 3.5rem 1rem;
|
|
5
6
|
}
|
|
6
7
|
|
|
@@ -18,6 +19,7 @@ header .top .title {
|
|
|
18
19
|
|
|
19
20
|
header .top .subtitle {
|
|
20
21
|
font-size: 0.85rem;
|
|
22
|
+
padding-left: 0.3rem;
|
|
21
23
|
font-family: 'Inter Extra Bold';
|
|
22
24
|
color: var(--light-yellow);
|
|
23
25
|
text-transform: uppercase;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { postsMetaData } from '../main';
|
|
2
1
|
import { beautifyDate, filterByUrlQueryIfPresent } from 'blazed-past-us';
|
|
3
2
|
|
|
4
|
-
export default function home(tags) {
|
|
3
|
+
export default function home(tags, postsMetadata) {
|
|
5
4
|
const baseURL = import.meta.env.BASE_URL;
|
|
6
|
-
const postsToShow = filterByUrlQueryIfPresent(
|
|
5
|
+
const postsToShow = filterByUrlQueryIfPresent(postsMetadata, tags);
|
|
7
6
|
|
|
8
7
|
return postsToShow
|
|
9
8
|
.map(
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { beautifyDate, getPostData
|
|
2
|
-
import { postsMetaData, postsHTML } from '../main';
|
|
1
|
+
import { beautifyDate, getPostData } from 'blazed-past-us';
|
|
3
2
|
|
|
4
|
-
export default async function post(slug) {
|
|
5
|
-
const title = getPostData(
|
|
6
|
-
const date = beautifyDate(getPostData(
|
|
3
|
+
export default async function post(slug, postsMetadata, htmlContent) {
|
|
4
|
+
const title = getPostData(postsMetadata, slug, 'title');
|
|
5
|
+
const date = beautifyDate(getPostData(postsMetadata, slug, 'created'));
|
|
7
6
|
|
|
8
7
|
return `
|
|
9
8
|
<div class="post">
|
|
10
9
|
<div class="title capitalize-first">${title}</div>
|
|
11
10
|
<div class="date">${date}</div>
|
|
12
|
-
${
|
|
11
|
+
${htmlContent}
|
|
13
12
|
</div>
|
|
14
13
|
`;
|
|
15
14
|
}
|
package/package.json
CHANGED
package/blazed-past-us-0.4.5.tgz
DELETED
|
Binary file
|
|
File without changes
|