docs: document options for static and live loader (#15)

* docs: adding jsdoc and updating README

* docs: document options for leafletLiveLoader

* docs: specify that a normal handle can be passed to loader options

* chore: changeset

authored by Dane Miller and committed by GitHub 8922bb1d 2ed94d4c

+5
.changeset/sweet-rockets-fetch.md
···
··· 1 + --- 2 + "@nulfrost/leaflet-loader-astro": patch 3 + --- 4 + 5 + Add JSDoc comments for available loader options for leafletStaticLoader and leafletLiveLoader
+43 -4
README.md
··· 15 16 ## Usage 17 18 - ### Build-time loader: leafletStaticLoader (recommended) 19 20 ```ts 21 // src/content.config.ts ··· 23 import { leafletStaticLoader } from "@nulfrost/leaflet-loader-astro"; 24 25 const documents = defineCollection({ 26 - loader: leafletStaticLoader({ repo: "did:plc:qttsv4e7pu2jl3ilanfgc3zn" }), 27 }); 28 29 export const collections = { documents }; ··· 81 82 <Content /> 83 ``` 84 85 - ### Live loader: leafletLiveLoader 86 87 ```ts 88 // astro.config.mjs ··· 104 import { leafletLiveLoader } from "@nulfrost/leaflet-loader-astro"; 105 106 const documents = defineLiveCollection({ 107 - loader: leafletLiveLoader({ repo: "did:plc:qttsv4e7pu2jl3ilanfgc3zn" }), 108 }); 109 110 export const collections = { documents }; ··· 158 159 <Content /> 160 ``` 161 162 ## License 163
··· 15 16 ## Usage 17 18 + <details> 19 + <summary>Build-time loader: leafletStaticLoader **(recommended)**</summary> 20 21 ```ts 22 // src/content.config.ts ··· 24 import { leafletStaticLoader } from "@nulfrost/leaflet-loader-astro"; 25 26 const documents = defineCollection({ 27 + loader: leafletStaticLoader({ repo: "did:plc:qttsv4e7pu2jl3ilanfgc3zn" }), // or repo: dane.is.extraordinarily.cool 28 }); 29 30 export const collections = { documents }; ··· 82 83 <Content /> 84 ``` 85 + </details> 86 87 + <details> 88 + <summary>Live loader: leafletLiveLoader</summary> 89 90 ```ts 91 // astro.config.mjs ··· 107 import { leafletLiveLoader } from "@nulfrost/leaflet-loader-astro"; 108 109 const documents = defineLiveCollection({ 110 + loader: leafletLiveLoader({ repo: "did:plc:qttsv4e7pu2jl3ilanfgc3zn" }), // or repo: dane.is.extraordinarily.cool 111 }); 112 113 export const collections = { documents }; ··· 161 162 <Content /> 163 ``` 164 + 165 + </details> 166 + 167 + ## Loader Options 168 + 169 + ### Static Loader 170 + 171 + ```ts 172 + leafletStaticLoader() 173 + ``` 174 + 175 + `repo`: This can be either your DID (did:plc:qttsv4e7pu2jl3ilanfgc3zn) or your handle (dane.is.extraordinarily.cool) 176 + 177 + `limit`: How many leaflet documents to return when calling `getCollection`. The default is 50 and the range is from 1 to 100. 178 + 179 + `reverse`: Whether or not to return the leaflet documents in reverse order. By default this is false. 180 + 181 + ### Live Loader 182 + 183 + ```ts 184 + leafletLiveLoader() 185 + ``` 186 + 187 + `repo`: This can be either your DID (did:plc:qttsv4e7pu2jl3ilanfgc3zn) or your handle (dane.is.extraordinarily.cool) 188 + 189 + > [!NOTE] 190 + > `getLiveCollection` supports a second argument where you can add additional filters, similar to the options you have access to for `leafletStaticLoader` 191 + 192 + ```ts 193 + getLiveCollection() 194 + ``` 195 + 196 + `limit`: How many leaflet documents to return when calling `getCollection`. The default is 50 and the range is from 1 to 100. 197 + 198 + `reverse`: Whether or not to return the leaflet documents in reverse order. By default this is false. 199 + 200 201 ## License 202
+3 -2
lib/leaftlet-static-loader.ts
··· 19 export function leafletStaticLoader( 20 options: StaticLeafletLoaderOptions, 21 ): Loader { 22 - const { repo, limit } = options; 23 24 if (!repo || typeof repo !== "string") { 25 throw new LiveLoaderError( ··· 63 rpc, 64 repo, 65 cursor, 66 - limit: 100, 67 }); 68 for (const document of documents) { 69 if (limit && count >= limit) {
··· 19 export function leafletStaticLoader( 20 options: StaticLeafletLoaderOptions, 21 ): Loader { 22 + const { repo, limit, reverse } = options; 23 24 if (!repo || typeof repo !== "string") { 25 throw new LiveLoaderError( ··· 63 rpc, 64 repo, 65 cursor, 66 + reverse, 67 + limit: 50, 68 }); 69 for (const document of documents) { 70 if (limit && count >= limit) {
+8 -3
lib/types.ts
··· 5 6 export interface LiveLeafletLoaderOptions { 7 /** 8 - * @description Your repo is your DID (did:plc... or did:web...). You can find this information using: https://pdsls.dev 9 */ 10 repo: string; 11 } 12 13 export interface StaticLeafletLoaderOptions { 14 /** 15 - * @description Your repo is your DID (did:plc... or did:web...). You can find this information using: https://pdsls.dev 16 */ 17 repo: string; 18 - filter?: string; 19 /** 20 * @default 50 21 */ 22 limit?: number; 23 } 24 25 export interface LeafletDocumentRecord {
··· 5 6 export interface LiveLeafletLoaderOptions { 7 /** 8 + * @description Your repo is your DID (did:plc... or did:web...) or handle (username.bsky.social). You can find this information using: https://pdsls.dev 9 */ 10 repo: string; 11 } 12 13 export interface StaticLeafletLoaderOptions { 14 /** 15 + * @description Your repo is your DID (did:plc... or did:web...) or handle (username.bsky.social). You can find this information using: https://pdsls.dev 16 */ 17 repo: string; 18 /** 19 + * @description The number of records leaflet records to return for getCollection, the default being 50. The range can be from 1 to 100. 20 * @default 50 21 */ 22 limit?: number; 23 + /** 24 + * @description Whether or not the records should be returned in reverse order. 25 + * @default undefined 26 + */ 27 + reverse?: boolean; 28 } 29 30 export interface LeafletDocumentRecord {
+1 -1
lib/utils.ts
··· 1 import type {} from "@atcute/atproto"; 2 - import { type Handle, is } from "@atcute/lexicons"; 3 import { AtUri, UnicodeString } from "@atproto/api"; 4 import katex from "katex"; 5 import sanitizeHTML from "sanitize-html";
··· 1 import type {} from "@atcute/atproto"; 2 + import { is } from "@atcute/lexicons"; 3 import { AtUri, UnicodeString } from "@atproto/api"; 4 import katex from "katex"; 5 import sanitizeHTML from "sanitize-html";