Files
boris/node_modules/applesauce-content/dist/text/gallery.js
Gigi 5d53a827e0 feat: initialize markr nostr bookmark client
- Add project structure with TypeScript, React, and Vite
- Implement nostr authentication using browser extension (NIP-07)
- Add NIP-51 compliant bookmark fetching and display
- Create minimal UI with login and bookmark components
- Integrate applesauce-core and applesauce-react libraries
- Add responsive styling with dark/light mode support
- Include comprehensive README with setup instructions

This is a minimal MVP for a nostr bookmark client that allows users to
view their bookmarks according to NIP-51 specification.
2025-10-02 07:17:07 +02:00

49 lines
1.9 KiB
JavaScript

import { convertToUrl, getURLFilename, IMAGE_EXT } from "applesauce-core/helpers/url";
/** Group images into galleries in an ATS tree */
export function galleries(types = IMAGE_EXT) {
return (tree) => {
let links = [];
const commit = (index) => {
// only create a gallery if there are more than a single image
if (links.length > 1) {
const start = tree.children.indexOf(links[0]);
const end = tree.children.indexOf(links[links.length - 1]);
// replace all nodes with a gallery
tree.children.splice(start, 1 + end - start, { type: "gallery", links: links.map((l) => l.href) });
links = [];
// return new cursor
return end - 1;
}
else {
links = [];
return index;
}
};
for (let i = 0; i < tree.children.length; i++) {
const node = tree.children[i];
try {
if (node.type === "link") {
const url = convertToUrl(node.href);
const filename = getURLFilename(url);
if (filename && types.some((ext) => filename.endsWith(ext))) {
links.push(node);
}
else {
i = commit(i);
}
}
else if (node.type === "text" && links.length > 0) {
const isEmpty = node.value === "\n" || !node.value.match(/[^\s]/g);
if (!isEmpty)
i = commit(i);
}
}
catch (error) {
i = commit(i);
}
}
// Do one finally commit, just in case a link is the last element in the list
commit(tree.children.length);
};
}