Skip to content

Instantly share code, notes, and snippets.

@kLiHz
Created March 17, 2025 04:46
Show Gist options
  • Save kLiHz/0396fba0c0c1ac9f27ed40431853e853 to your computer and use it in GitHub Desktop.
Save kLiHz/0396fba0c0c1ac9f27ed40431853e853 to your computer and use it in GitHub Desktop.
HNote data v2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HNote Data v2</title>
</head>
<body>
<style>
body {
font-family: 'IBM Plex Sans SC', sans-serif;
}
#container {
> ul {
list-style-type: none;
}
}
</style>
<div id="container">
</div>
</body>
<script type="module">
/**
* @typedef {object} FolderMeta - creates a new type named 'Folder'
* @property {number} createdAt - ms timestamp
* @property {string} name - string
* @property {string} objectId - any string, or uuid
* @property {number} position - int32
* @property {number} updatedAt - ms timestamp
*/
/**
* @typedef {object} NoteMeta - creates a new type named 'Folder'
* @property {number} createdAt - ms timestamp
* @property {boolean} done
* @property {boolean} favorite
* @property {string} folderId
* @property {boolean} hasImage
* @property {string} images
* @property {boolean} lock
* @property {boolean} markdown
* @property {string} objectId - any string, or uuid
* @property {number} pinedTime
* @property {number} positionInFolder - int32 / 0
* @property {string} title
* @property {number} updatedAt - ms timestamp
*/
const metaJson = await fetch('/meta.json');
/** @type {{folders:FolderMeta[], notes:NoteMeta[], res: object[], updatedAt:number}} */
const {folders, notes} = await metaJson.json();
/** @type {Map<string, HTMLOListElement>} */
const folderItemLists = new Map();
const ul = document.createElement('ul');
for (const {name, objectId} of folders) {
const details = document.createElement('details');
{
const sumary = document.createElement('summary');
sumary.textContent = name;
details.appendChild(sumary);
const ol = document.createElement('ol');
details.appendChild(ol);
folderItemLists.set(objectId, ol);
}
const li = document.createElement('li');
li.appendChild(details);
ul.appendChild(li);
}
for (const {folderId, objectId, updatedAt, title} of notes) {
const li = document.createElement('li');
li.textContent = title;
folderItemLists.get(folderId).appendChild(li);
}
const div = document.getElementById('container');
div.replaceChildren(ul);
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment