blazed-past-us 0.3.4 → 0.3.7
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 +10 -1
- package/dist/engine/getters.js +1 -1
- package/dist/engine/utils.d.ts +1 -2
- package/dist/engine/utils.js +1 -13
- package/dist/template/index.html +1 -2
- package/dist/template/src/config.json +1 -1
- package/dist/template/src/main.js +6 -7
- package/dist/template/src/router.js +18 -8
- package/dist/template/src/views/home.js +1 -1
- package/dist/template/vite.config.js +5 -0
- package/package.json +1 -1
- package/blazed-past-us-0.3.1.tgz +0 -0
package/README.md
CHANGED
|
@@ -17,7 +17,16 @@ _"I don't know… shall we see?"_
|
|
|
17
17
|
**Silver Surfer looked dubious and curious:**
|
|
18
18
|
_"Very well… let the cosmos bear witness."_
|
|
19
19
|
|
|
20
|
-
##
|
|
20
|
+
## About the framework
|
|
21
|
+
|
|
22
|
+
- Designed for static hosting environments (e.g. GitHub Pages) — no server-side rewrites required.
|
|
23
|
+
- Uses hash routing.
|
|
24
|
+
- Fetches static JSON.
|
|
25
|
+
- Fetches HTML fragments.
|
|
26
|
+
- Avoids history API clean URLs.
|
|
27
|
+
- Doesn’t rely on server fallback.
|
|
28
|
+
|
|
29
|
+
## How to write posts ?
|
|
21
30
|
|
|
22
31
|
- The post file name will be the title.
|
|
23
32
|
- There is no need to add the title within the .md file, this will be set by the meta data.
|
package/dist/engine/getters.js
CHANGED
|
@@ -3,7 +3,7 @@ function getPostData(postsMetaData, slug, option) {
|
|
|
3
3
|
}
|
|
4
4
|
async function getPostHtml(postsMetaData, root, baseURL, postSlug) {
|
|
5
5
|
const filename = postsMetaData.find((post) => post.slug === postSlug)?.filename;
|
|
6
|
-
const html = await fetch(`${baseURL}
|
|
6
|
+
const html = await fetch(`${baseURL}posts/${filename}`)
|
|
7
7
|
.then((resp) => resp.text())
|
|
8
8
|
.then((htmlString) => (root.innerHTML = htmlString))
|
|
9
9
|
.catch((error) => console.error(error));
|
package/dist/engine/utils.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { MsgColor } from '../types';
|
|
2
2
|
declare function postExists(postsMetaData: any[], slug: string): boolean;
|
|
3
3
|
declare function beautifyDate(d: Date | undefined): undefined | string;
|
|
4
|
-
declare function showCosmicSpeed(document: HTMLDocument, elementID: string): void;
|
|
5
4
|
declare function inject(root: HTMLElement, html: string): void;
|
|
6
5
|
declare function log(msg: string, color: MsgColor): void;
|
|
7
6
|
declare function boltRotator(document: HTMLDocument, elementID: string): void;
|
|
8
7
|
declare function setTitle(document: HTMLDocument, elementID: string, packageName: string): void;
|
|
9
|
-
export { postExists, beautifyDate,
|
|
8
|
+
export { postExists, beautifyDate, inject, log, boltRotator, setTitle };
|
package/dist/engine/utils.js
CHANGED
|
@@ -13,18 +13,6 @@ function beautifyDate(d) {
|
|
|
13
13
|
month: 'long',
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
|
-
function showCosmicSpeed(document, elementID) {
|
|
17
|
-
const el = document.getElementById(elementID);
|
|
18
|
-
if (el) {
|
|
19
|
-
new PerformanceObserver((list) => {
|
|
20
|
-
list.getEntries().forEach((en) => {
|
|
21
|
-
if (en.name === 'first-contentful-paint') {
|
|
22
|
-
el.innerHTML = `<span>${en.startTime} ms</span>`;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}).observe({ type: 'paint', buffered: true });
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
16
|
function inject(root, html) {
|
|
29
17
|
root.innerHTML = html;
|
|
30
18
|
}
|
|
@@ -57,4 +45,4 @@ function setTitle(document, elementID, packageName) {
|
|
|
57
45
|
el.innerText = packageName.replaceAll('-', ' ');
|
|
58
46
|
}
|
|
59
47
|
}
|
|
60
|
-
export { postExists, beautifyDate,
|
|
48
|
+
export { postExists, beautifyDate, inject, log, boltRotator, setTitle };
|
package/dist/template/index.html
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import config from './config.json';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import * as blazed from 'blazed-past-us';
|
|
3
|
+
import initRouter from './router';
|
|
4
4
|
import pkg from '../package.json';
|
|
5
5
|
|
|
6
6
|
const root = document.getElementById(config.root_id);
|
|
7
|
-
const postsMetaData = await getPostsMetaData(import.meta.env.BASE_URL, config);
|
|
7
|
+
const postsMetaData = await blazed.getPostsMetaData(import.meta.env.BASE_URL, config);
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
initRouter(root, postsMetaData);
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* ----------------------------
|
|
@@ -15,8 +15,7 @@ router(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
|
-
setTitle(document, config.title_id, pkg.name);
|
|
19
|
-
boltRotator(document, config.logo_wrapper_id);
|
|
20
|
-
showCosmicSpeed(document, config.speed_element_id);
|
|
18
|
+
blazed.setTitle(document, config.title_id, pkg.name);
|
|
19
|
+
blazed.boltRotator(document, config.logo_wrapper_id);
|
|
21
20
|
|
|
22
21
|
export { root, postsMetaData };
|
|
@@ -4,8 +4,21 @@ import home from './views/home';
|
|
|
4
4
|
import post from './views/post';
|
|
5
5
|
import notFound from './views/notFound';
|
|
6
6
|
|
|
7
|
-
export default
|
|
8
|
-
|
|
7
|
+
export default function initRouter(root, postsMetaData) {
|
|
8
|
+
// Render current route immediately.
|
|
9
|
+
handleRoute(root, postsMetaData);
|
|
10
|
+
|
|
11
|
+
window.addEventListener('hashchange', () => handleRoute(root, postsMetaData));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* GitHub Pages is a static file server. It does not understand client-side routing.
|
|
16
|
+
* Everything after # stays client-side.
|
|
17
|
+
*
|
|
18
|
+
* This is the reason why we use hash routing.
|
|
19
|
+
*/
|
|
20
|
+
async function handleRoute(root, postsMetaData) {
|
|
21
|
+
const pathname = removeHash(window.location.hash);
|
|
9
22
|
const urlParams = new URLSearchParams(window.location.search);
|
|
10
23
|
const views = { home, post, notFound };
|
|
11
24
|
|
|
@@ -22,10 +35,7 @@ export default async function router(root, postsMetaData) {
|
|
|
22
35
|
render('404', root, views, postsMetaData);
|
|
23
36
|
}
|
|
24
37
|
|
|
25
|
-
// Removes
|
|
26
|
-
function
|
|
27
|
-
return
|
|
28
|
-
.split('/')
|
|
29
|
-
.filter((name) => !import.meta.env.BASE_URL.split('/').includes(name))
|
|
30
|
-
.join('');
|
|
38
|
+
// Removes "#/" from the location hash.
|
|
39
|
+
function removeHash(locationHash) {
|
|
40
|
+
return locationHash.split('/').splice(1).join('/');
|
|
31
41
|
}
|
|
@@ -8,7 +8,7 @@ export default function home(tag) {
|
|
|
8
8
|
.filter((post) => (tag ? post.tags.includes(tag) : true))
|
|
9
9
|
.map(
|
|
10
10
|
(post) => `
|
|
11
|
-
<a href="${baseURL}
|
|
11
|
+
<a href="${baseURL}#/${post.slug}">
|
|
12
12
|
<div class="post-card">
|
|
13
13
|
<div class="title capitalize-first">${post.title}</div>
|
|
14
14
|
<div class="date">${beautifyDate(post.created)}</div>
|
package/package.json
CHANGED
package/blazed-past-us-0.3.1.tgz
DELETED
|
Binary file
|