Documentation
¶
Overview ¶
Package docs searches and reads the Re:Earth documentation through the site's llms-full.txt: every page of docs.reearth.io in one Markdown file.
Index ¶
Constants ¶
const DefaultSite = "https://docs.reearth.io"
DefaultSite is the documentation site. REEARTH_DOCS_URL overrides it.
Variables ¶
var ErrNoPages = errors.New("llms-full.txt contains no pages")
ErrNoPages means that the site served an llms-full.txt with no pages in it, such as an empty body or an HTML error page.
var ErrNotFound = errors.New("no such page")
ErrNotFound is returned by Find when no page matches.
Functions ¶
This section is empty.
Types ¶
type AmbiguousError ¶
AmbiguousError is returned by Find when several pages share the title.
func (*AmbiguousError) Error ¶
func (e *AmbiguousError) Error() string
type CacheError ¶
type CacheError struct{ Err error }
CacheError is the warning Load returns when it could not save a fresh copy. The fresh pages are returned anyway.
func (*CacheError) Error ¶
func (e *CacheError) Error() string
func (*CacheError) Unwrap ¶
func (e *CacheError) Unwrap() error
type Match ¶
type Match struct {
ID string `json:"id"`
Title string `json:"title"`
URL string `json:"url,omitempty"`
Summary string `json:"summary"`
}
Match is one search result.
type Page ¶
type Page struct {
// ID names the page for `docs read`: the URL path when the file carries
// page URLs, otherwise the title. When several pages would share an ID,
// each of them is numbered. Numbers follow file order, so they can change
// when pages are added to the site.
ID string `json:"id"`
Title string `json:"title"`
URL string `json:"url,omitempty"`
Description string `json:"description"`
Body string `json:"-"`
}
Page is one page of the documentation.
func Find ¶
Find returns the page named by ref: an ID, a title, or a page URL or URL path. IDs are unique and never a shared title, so an ID always resolves; a title that several pages share is an *AmbiguousError listing their IDs. The ref is tried verbatim first, so titles with slashes or that look like URLs resolve too.
func Parse ¶
Parse splits llms-full.txt into pages. The generator writes each page as
# Title Source: https://docs.reearth.io/ja/cms/ (only on newer builds) > Description Body...
A heading followed by anything other than a description is a heading inside a page, not a new page. Text before the first page, such as the <SYSTEM> line, is dropped.
type Source ¶
type Source struct {
Site string
Dir string
Client *http.Client
// MaxAge is how long a copy is used without asking the site for changes.
MaxAge time.Duration
Now func() time.Time
}
Source downloads llms-full.txt and keeps a copy in a directory under Dir that is named after Site, so that switching sites never mixes their copies.
func (*Source) Load ¶
Load returns at least one page, or an error. A fresh copy is used as is. An older one is revalidated with a conditional request; when the site cannot be reached, answers with an error status or serves no pages, the copy is used anyway and warn is a *StaleError. When a fresh download cannot be saved, warn is a *CacheError.
type StaleError ¶
type StaleError struct{ Err error }
StaleError is the warning Load returns when it falls back to the cached copy because the site could not be used.
func (*StaleError) Error ¶
func (e *StaleError) Error() string
func (*StaleError) Unwrap ¶
func (e *StaleError) Unwrap() error
type StatusError ¶
StatusError is a response other than 200 or 304.
func (*StatusError) Error ¶
func (e *StatusError) Error() string