HammeriteManual
Editor. Inherits RefCounted
The manual: its sections, their pages, links between them and search over all of it.
A page is named by its place in a virtual tree, <section>/<page>.md, whichever directory it was read from. That is the tree a published copy of the manual has on a website, so a link between two pages works the same in both.
Methods
| Returns | Method |
|---|---|
void | register_section(id: StringName, title: String, directory: String, order: int = -1) |
void | unregister_section(id: StringName) |
void | add_pages(id: StringName, directory: String) |
void | remove_pages(id: StringName, directory: String) |
HammeriteManualSection[] | sections() |
HammeriteManualSection | get_section(id: StringName) |
PackedStringArray | get_section_directories(id: StringName) |
String | home() |
HammeriteManualPage[] | pages_in(id: StringName) |
HammeriteManualPage[] | all_pages() |
HammeriteManualPage | get_page(path: String) |
String | get_page_file(path: String) |
bool | has_location(location: String) |
bool | is_external(href: String) static |
String | resolve(from: String, href: String) |
HammeriteManual.SearchHit[] | search(query: String, limit: int = 30) |
PackedStringArray | validate() |
Signals
changed
signal changed()
The set of sections or their directories changed. Not emitted when a page's file is edited on disk; get_page() picks that up on its own.
Constants
INDEX
const INDEX = "index.md"
The file name of a section's front page, listed first in it and opened by home().
Method descriptions
register_section()
func register_section(id: StringName, title: String, directory: String, order: int = -1) -> void
Adds a section read from directory; order places it in the index, and a negative one after every section given an order, whenever those are registered - the sections placed last in the order they were registered. Registering an id again replaces it.
unregister_section()
func unregister_section(id: StringName) -> void
Removes section id. Pages added to it with add_pages() are remembered, and come back if the id is registered again.
add_pages()
func add_pages(id: StringName, directory: String) -> void
Adds the pages in directory to section id. May come before the section itself is registered. A page of the same name as one the section already has does not replace it.
remove_pages()
func remove_pages(id: StringName, directory: String) -> void
Undoes add_pages() for directory. Nothing happens if it was not added.
sections()
func sections() -> HammeriteManualSection[]
Every section, in index order: by order, then by id, and those placed last after them in the order they were registered. Copies: change a section by registering it again.
get_section()
func get_section(id: StringName) -> HammeriteManualSection
Section id, or null: a copy, as sections() hands out.
get_section_directories()
func get_section_directories(id: StringName) -> PackedStringArray
Where section id's pages are read from, its own directory first and then any added. A copy; empty for an unknown id.
home()
func home() -> String
Where a new tab opens: the first section's index.
pages_in()
func pages_in(id: StringName) -> HammeriteManualPage[]
Section id's pages, index first, then by their order.
all_pages()
func all_pages() -> HammeriteManualPage[]
Every page of every section, in index order. Reads each from disk unless already cached and unchanged.
get_page()
func get_page(path: String) -> HammeriteManualPage
The page at path (<section>/<page>.md, an anchor is ignored), or null. Read again when the file has changed since, so an edited page shows without restarting.
get_page_file()
func get_page_file(path: String) -> String
Where the page at path is read from, or empty when there is no such page.
has_location()
func has_location(location: String) -> bool
Whether location is a page, and its anchor (if any) one of the page's headings.
is_external()
static func is_external(href: String) -> bool
Whether href leaves the manual: an http, https or mailto link.
resolve()
func resolve(from: String, href: String) -> String
Where href, written on the page at from, leads: <section>/<page>.md, with its #anchor when it has one. Empty when it leads to no page. The anchor is not checked; see has_location().
search()
func search(query: String, limit: int = 30) -> HammeriteManual.SearchHit[]
Every page matching every word of query, best first. A word in the title counts for most, then in the keywords, then in a heading, then in the text.
validate()
func validate() -> PackedStringArray
Every way the shipped pages are broken: format, links to pages that do not exist and anchors that no heading has. One line each, naming the page.
class SearchHit
One result of search().
Properties
| Type | Name | Default |
|---|---|---|
String | location | "" |
String | title | "" |
String | section_title | "" |
String | snippet | "" |
int | score | 0 |
Property descriptions
location
var location: String = ""
Where to go: <section>/<page>.md, with #anchor when a heading is what matched.
title
var title: String = ""
The page's title.
section_title
var section_title: String = ""
The title of the section the page is in, for a result list that mixes sections.
snippet
var snippet: String = ""
Up to about 160 characters of the page's text around the first match, with ellipses where it was cut.
score
var score: int = 0
How well it matched; higher is better. Only meaningful against other hits of the same search.