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.
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.
@@ -1,13 +1,8 @@
1
- import type { PostMetaData, Config, PostDataType } from '../types';
2
- declare function getPostData(postsMetaData: PostMetaData[], slug: string, option: PostDataType): string | string[] | Date | undefined;
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, getAllPostsHTML, getPostsMetaData, getTitle, getTags, getBrief, getColoredTagsHTML, getSlug, };
8
+ export { getPostData, getTitle, getTags, getBrief, getColoredTagsHTML, getSlug };
@@ -1,32 +1,5 @@
1
- function getPostData(postsMetaData, slug, option) {
2
- return postsMetaData.find((post) => post.slug === slug)?.[option];
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, getAllPostsHTML, getPostsMetaData, getTitle, getTags, getBrief, getColoredTagsHTML, getSlug, };
45
+ export { getPostData, getTitle, getTags, getBrief, getColoredTagsHTML, getSlug };
@@ -1,3 +1,3 @@
1
- import { Views, PostMetaData } from '../types.js';
2
- declare function render(view: string, root: HTMLElement, views: Views, postsMetaData: PostMetaData[], postTagsFilter?: string, postSlug?: string): void;
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 };
@@ -1,14 +1,15 @@
1
1
  import { postExists, inject } from './utils.js';
2
- function render(view, root, views, postsMetaData, postTagsFilter, postSlug) {
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(postsMetaData, postSlug)) {
11
- post(postSlug).then((html) => inject(r, html));
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,5 @@
1
+ import { Config, PostMetadata, PostHTML } from '../types';
2
+ export declare function fetchResources(config: Config): Promise<void | {
3
+ postsMetadata: PostMetadata[];
4
+ postsHTML: PostHTML[];
5
+ }>;
@@ -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
+ }
@@ -1,15 +1,15 @@
1
- import { MsgColor, PostMetaData } from '../types';
2
- declare function postExists(postsMetaData: any[], slug: string): boolean;
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 boltRotator(document: HTMLDocument): void;
8
- declare function setTitle(document: HTMLDocument, packageName: string): void;
9
- declare function filterByUrlQueryIfPresent(postsMetaData: PostMetaData[], tags: string[]): PostMetaData[];
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, boltRotator, setTitle, getPathnameFromLocationHash, filterByUrlQueryIfPresent, getLocationHashSpecifics, };
15
+ export { postExists, beautifyDate, inject, log, activateBoltRotator, setTitleAndSubtitle, getPathnameFromLocationHash, filterByUrlQueryIfPresent, getLocationHashSpecifics, };
@@ -1,7 +1,7 @@
1
1
  import chalk from 'chalk';
2
2
  import pkg from '../../package.json' with { type: 'json' };
3
- function postExists(postsMetaData, slug) {
4
- return postsMetaData.some((post) => post.slug === slug);
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 boltRotator(document) {
40
- const el = document.querySelector('.logo');
41
- if (el) {
42
- el.classList.add('rotate');
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 setTitle(document, packageName) {
46
- const el = document.querySelector('.title');
47
- if (el) {
48
- el.innerHTML = packageName.replaceAll('-', ' ');
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(postsMetaData, tags) {
52
- return postsMetaData.filter((post) => tags ? tags.some((tag) => post.tags.includes(tag)) : true);
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, boltRotator, setTitle, getPathnameFromLocationHash, filterByUrlQueryIfPresent, getLocationHashSpecifics, };
68
+ export { postExists, beautifyDate, inject, log, activateBoltRotator, setTitleAndSubtitle, getPathnameFromLocationHash, filterByUrlQueryIfPresent, getLocationHashSpecifics, };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './engine/getters';
2
2
  export * from './engine/utils';
3
3
  export * from './engine/render';
4
+ export * from './engine/requests';
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './engine/getters';
2
2
  export * from './engine/utils';
3
3
  export * from './engine/render';
4
+ export * from './engine/requests';
@@ -1,4 +1,4 @@
1
- import { PostMetaData } from '../types';
1
+ import { PostMetadata } from '../types';
2
2
  declare function writeTransformedPostFile(outputPath: string, postHtmlContent: string, filename: string): Promise<void>;
3
- declare function generatePostMetadata(data: Array<PostMetaData>, filePath: string, htmlFilename: string, postTags: string[]): Promise<void>;
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/moonlight-li.json'), 'utf-8')),
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)
@@ -17,8 +17,7 @@
17
17
  <div>
18
18
  <div class="top">
19
19
  <a class="title" href="#/"></a>
20
- <!-- Feel free to change or remove the subtitle -->
21
- <div class="subtitle">let the cosmos bear witness</div>
20
+ <div class="subtitle"></div>
22
21
  </div>
23
22
  </div>
24
23
  </header>
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "base_url": "/blog/",
3
- "posts_data_path": "posts/data.json",
4
- "root_id": "root",
3
+ "subtitle": "notes from a dev...",
5
4
  "tags": {
6
5
  "javascript": { "color": "#f5dd42" },
7
6
  "typescript": { "color": "#42adf5" },
@@ -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(config.root_id);
7
- const postsMetaData = await blazed.getPostsMetaData(import.meta.env.BASE_URL, config);
6
+ const root = document.getElementById('root');
7
+ const { postsMetadata, postsHTML } = await blazed.fetchResources(config);
8
8
 
9
- initRouter(root, postsMetaData);
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.setTitle(document, pkg.name);
19
- blazed.boltRotator(document);
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, postsMetaData) {
7
- routeRenderer(root, postsMetaData);
8
- window.addEventListener('hashchange', () => routeRenderer(root, postsMetaData));
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, postsMetaData) {
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, postsMetaData, urlParams.get('tags'));
19
+ render('home', root, views, postsMetadata, postsHTML, urlParams.get('tags'));
18
20
  break;
19
21
 
20
- case postExists(postsMetaData, pathname):
21
- render('post', root, views, postsMetaData, undefined, pathname);
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, postsMetaData);
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(postsMetaData, tags);
5
+ const postsToShow = filterByUrlQueryIfPresent(postsMetadata, tags);
7
6
 
8
7
  return postsToShow
9
8
  .map(
@@ -1,15 +1,14 @@
1
- import { beautifyDate, getPostData, getPostHtml } from 'blazed-past-us';
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(postsMetaData, slug, 'title');
6
- const date = beautifyDate(getPostData(postsMetaData, slug, 'created'));
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
- ${postsHTML.find((post) => post.slug === slug).html}
11
+ ${htmlContent}
13
12
  </div>
14
13
  `;
15
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blazed-past-us",
3
- "version": "0.4.5",
3
+ "version": "0.5.5",
4
4
  "description": "A static blog framework made for developers that allows content to be written in Markdown directly from the IDE.",
5
5
  "license": "MIT",
6
6
  "author": "gass-git",
Binary file