blazed-past-us 0.4.1 → 0.4.2

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/README.md CHANGED
@@ -33,6 +33,10 @@ _"Very well… let the cosmos bear witness."_
33
33
  - Post tags are written in every post on the very top as `tag1, tag2,...`
34
34
  - The descriptions of the posts will be a brief showcase of the first paragraph (below the tags).
35
35
 
36
+ ## Useful notes
37
+
38
+ - Append `/#/?tags=` to the base URL to filter home page posts by tag.
39
+
36
40
  ## Installation
37
41
 
38
42
  ### Set up scaffold:
@@ -1,5 +1,5 @@
1
1
  import type { PostMetaData, Config, PostDataType } from '../types';
2
- declare function getPostData(postsMetaData: PostMetaData[], slug: string, option: PostDataType): string | Date | undefined;
2
+ declare function getPostData(postsMetaData: PostMetaData[], slug: string, option: PostDataType): string | string[] | Date | undefined;
3
3
  declare function getAllPostsHTML(postsMetaData: PostMetaData[], baseURL: string): Promise<{
4
4
  slug: string;
5
5
  html: string | void;
@@ -1,8 +1,10 @@
1
- import { MsgColor } from '../types';
1
+ import { MsgColor, PostMetaData } from '../types';
2
2
  declare function postExists(postsMetaData: any[], slug: string): boolean;
3
+ declare function getPathnameFromLocationHash(locationHash: string): string;
3
4
  declare function beautifyDate(d: Date | undefined): undefined | string;
4
5
  declare function inject(root: HTMLElement, html: string): void;
5
6
  declare function log(msg: string, color: MsgColor): void;
6
7
  declare function boltRotator(document: HTMLDocument, elementID: string): void;
7
8
  declare function setTitle(document: HTMLDocument, elementID: string, packageName: string): void;
8
- export { postExists, beautifyDate, inject, log, boltRotator, setTitle };
9
+ declare function filterByUrlQueryIsPresent(postsMetaData: PostMetaData[], tags: string[]): PostMetaData[];
10
+ export { postExists, beautifyDate, inject, log, boltRotator, setTitle, getPathnameFromLocationHash, filterByUrlQueryIsPresent, };
@@ -3,6 +3,9 @@ import pkg from '../../package.json' with { type: 'json' };
3
3
  function postExists(postsMetaData, slug) {
4
4
  return postsMetaData.some((post) => post.slug === slug);
5
5
  }
6
+ function getPathnameFromLocationHash(locationHash) {
7
+ return locationHash.split('/').splice(1).join('/');
8
+ }
6
9
  function beautifyDate(d) {
7
10
  if (!d)
8
11
  return;
@@ -45,4 +48,7 @@ function setTitle(document, elementID, packageName) {
45
48
  el.innerText = packageName.replaceAll('-', ' ');
46
49
  }
47
50
  }
48
- export { postExists, beautifyDate, inject, log, boltRotator, setTitle };
51
+ function filterByUrlQueryIsPresent(postsMetaData, tags) {
52
+ return postsMetaData.filter((post) => tags ? tags.some((tag) => post.tags.includes(tag)) : true);
53
+ }
54
+ export { postExists, beautifyDate, inject, log, boltRotator, setTitle, getPathnameFromLocationHash, filterByUrlQueryIsPresent, };
@@ -1,5 +1,4 @@
1
- import { render } from 'blazed-past-us';
2
- import { postExists } from 'blazed-past-us';
1
+ import { render, postExists, getPathnameFromLocationHash } from 'blazed-past-us';
3
2
  import home from './views/home';
4
3
  import post from './views/post';
5
4
  import notFound from './views/notFound';
@@ -19,7 +18,7 @@ export default function initRouter(root, postsMetaData) {
19
18
  */
20
19
  async function handleRoute(root, postsMetaData) {
21
20
  const hashRoute = window.location.hash;
22
- const pathname = getPathname(hashRoute);
21
+ const pathname = getPathnameFromLocationHash(hashRoute);
23
22
  const queryString = hashRoute.split('?')[1] || '';
24
23
  const urlParams = new URLSearchParams(queryString);
25
24
  const views = { home, post, notFound };
@@ -36,8 +35,3 @@ async function handleRoute(root, postsMetaData) {
36
35
 
37
36
  render('404', root, views, postsMetaData);
38
37
  }
39
-
40
- // Removes "#/" from the location hash.
41
- function getPathname(locationHash) {
42
- return locationHash.split('/').splice(1).join('/');
43
- }
@@ -1,11 +1,11 @@
1
1
  import { postsMetaData } from '../main';
2
- import { beautifyDate } from 'blazed-past-us';
2
+ import { beautifyDate, filterByUrlQueryIfPresent } from 'blazed-past-us';
3
3
 
4
4
  export default function home(tags) {
5
5
  const baseURL = import.meta.env.BASE_URL;
6
+ const postsToShow = filterByUrlQueryIfPresent(postsMetaData, tags);
6
7
 
7
- const postsHtmlArray = postsMetaData
8
- .filter((post) => (tags ? tags.some((tag) => post.tags.includes(tag)) : true))
8
+ return postsToShow
9
9
  .map(
10
10
  (post) => `
11
11
  <a href="${baseURL}#/${post.slug}">
@@ -16,7 +16,6 @@ export default function home(tags) {
16
16
  </div>
17
17
  </a>
18
18
  `
19
- );
20
-
21
- return postsHtmlArray.join('');
19
+ )
20
+ .join('');
22
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blazed-past-us",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
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",