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 15 16 16 ## Usage 17 17 18 - ### Build-time loader: leafletStaticLoader (recommended) 18 + <details> 19 + <summary>Build-time loader: leafletStaticLoader **(recommended)**</summary> 19 20 20 21 ```ts 21 22 // src/content.config.ts ··· 23 24 import { leafletStaticLoader } from "@nulfrost/leaflet-loader-astro"; 24 25 25 26 const documents = defineCollection({ 26 - loader: leafletStaticLoader({ repo: "did:plc:qttsv4e7pu2jl3ilanfgc3zn" }), 27 + loader: leafletStaticLoader({ repo: "did:plc:qttsv4e7pu2jl3ilanfgc3zn" }), // or repo: dane.is.extraordinarily.cool 27 28 }); 28 29 29 30 export const collections = { documents }; ··· 81 82 82 83 <Content /> 83 84 ``` 85 + </details> 84 86 85 - ### Live loader: leafletLiveLoader 87 + <details> 88 + <summary>Live loader: leafletLiveLoader</summary> 86 89 87 90 ```ts 88 91 // astro.config.mjs ··· 104 107 import { leafletLiveLoader } from "@nulfrost/leaflet-loader-astro"; 105 108 106 109 const documents = defineLiveCollection({ 107 - loader: leafletLiveLoader({ repo: "did:plc:qttsv4e7pu2jl3ilanfgc3zn" }), 110 + loader: leafletLiveLoader({ repo: "did:plc:qttsv4e7pu2jl3ilanfgc3zn" }), // or repo: dane.is.extraordinarily.cool 108 111 }); 109 112 110 113 export const collections = { documents }; ··· 158 161 159 162 <Content /> 160 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 + 161 200 162 201 ## License 163 202
+3 -2
lib/leaftlet-static-loader.ts
··· 19 19 export function leafletStaticLoader( 20 20 options: StaticLeafletLoaderOptions, 21 21 ): Loader { 22 - const { repo, limit } = options; 22 + const { repo, limit, reverse } = options; 23 23 24 24 if (!repo || typeof repo !== "string") { 25 25 throw new LiveLoaderError( ··· 63 63 rpc, 64 64 repo, 65 65 cursor, 66 - limit: 100, 66 + reverse, 67 + limit: 50, 67 68 }); 68 69 for (const document of documents) { 69 70 if (limit && count >= limit) {
+8 -3
lib/types.ts
··· 5 5 6 6 export interface LiveLeafletLoaderOptions { 7 7 /** 8 - * @description Your repo is your DID (did:plc... or did:web...). You can find this information using: https://pdsls.dev 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 9 */ 10 10 repo: string; 11 11 } 12 12 13 13 export interface StaticLeafletLoaderOptions { 14 14 /** 15 - * @description Your repo is your DID (did:plc... or did:web...). You can find this information using: https://pdsls.dev 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 16 */ 17 17 repo: string; 18 - filter?: string; 19 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 20 * @default 50 21 21 */ 22 22 limit?: number; 23 + /** 24 + * @description Whether or not the records should be returned in reverse order. 25 + * @default undefined 26 + */ 27 + reverse?: boolean; 23 28 } 24 29 25 30 export interface LeafletDocumentRecord {
+1 -1
lib/utils.ts
··· 1 1 import type {} from "@atcute/atproto"; 2 - import { type Handle, is } from "@atcute/lexicons"; 2 + import { is } from "@atcute/lexicons"; 3 3 import { AtUri, UnicodeString } from "@atproto/api"; 4 4 import katex from "katex"; 5 5 import sanitizeHTML from "sanitize-html";