1
0
Fork 0
mirror of https://github.com/nbtca/docs.git synced 2026-09-19 23:05:53 +08:00
Data-only library for the NBTCA documents repository (nbtca/documents). Fetches and caches directory listings and markdown files from GitHub.
  • TypeScript 93.6%
  • JavaScript 6.4%
Find a file
2026-08-13 11:48:53 +08:00
.github/workflows fix: harden docs fetching and content indexing 2026-08-13 11:48:53 +08:00
scripts fix: harden docs fetching and content indexing 2026-08-13 11:48:53 +08:00
src fix: harden docs fetching and content indexing 2026-08-13 11:48:53 +08:00
.gitignore feat: initial @nbtca/docs library 2026-06-21 10:06:11 +08:00
.prettierignore feat: add document discovery and search (#2) 2026-08-12 13:53:59 +08:00
.prettierrc.json feat: add document discovery and search (#2) 2026-08-12 13:53:59 +08:00
eslint.config.mjs feat: add document discovery and search (#2) 2026-08-12 13:53:59 +08:00
LICENSE release: docs 0.2.3 2026-08-04 12:04:36 +08:00
package-lock.json feat: add document discovery and search (#2) 2026-08-12 13:53:59 +08:00
package.json feat: add document discovery and search (#2) 2026-08-12 13:53:59 +08:00
README.md feat: add document discovery and search (#2) 2026-08-12 13:53:59 +08:00
tsconfig.build.json feat: add document discovery and search (#2) 2026-08-12 13:53:59 +08:00
tsconfig.json fix: harden docs fetching and content indexing 2026-08-13 11:48:53 +08:00
vitest.config.ts feat: initial @nbtca/docs library 2026-06-21 10:06:11 +08:00

@nbtca/docs

Typed GitHub client for the NBTCA documents repository. It lists Markdown documents, reads raw content, caches successful responses, and falls back to stale data after transient failures. Rendering remains the consumer's responsibility.

Install

npm install @nbtca/docs

Usage

import { createDocsClient } from '@nbtca/docs';

const docs = createDocsClient();

const sections = await docs.listDir();
const documents = await docs.listAll();
const markdown = await docs.getFile('repair/guide.md');
const page = await docs.getDocument('repair/index.md');
const matches = await docs.search('repair', { pathPrefix: 'repair' });

API

createDocsClient(options?)

Option Default Description
owner 'nbtca' GitHub owner
repo 'documents' Repository name
branch 'main' Branch name or ref
token GITHUB_TOKEN or GH_TOKEN GitHub token
cacheTtlMs.dir 300000 Directory and tree cache TTL
cacheTtlMs.file 600000 File cache TTL

docs.listDir(path?)

Lists directories and Markdown files at a repository-relative path. The root path is used when path is omitted.

docs.getFile(path)

Returns raw file content.

docs.listAll()

Lists every Markdown file through GitHub's recursive tree API.

docs.listSections()

Returns top-level content sections with document counts and optional index paths.

docs.getDocument(path)

Returns content with its route, section, title, summary, and semantic component attributes. Component metadata covers PageHero, FactStrip, LinkCard, Split, TimelineEntry, and Figure without imposing a renderer.

docs.search(query, options?)

Searches paths, titles, summaries, Markdown text, and semantic component attributes. Results are ranked and include excerpts. Use pathPrefix to scope a search and limit to cap results.

docs.clear()

Clears all cached values and in-flight request bookkeeping.

DocsFetchError

Thrown when a request fails without usable stale data. Exposes path and HTTP status.

License

MIT