pub struct Publication {
pub kinds: Vec<PublishedKind>,
pub base_url: Option<String>,
}Expand description
A repository’s publication declaration, with the base URL its site is built for.
Read from PUBLICATION and the site’s base_url at request time, never compiled in:
this executable supervises repositories that have no site at all, and for those
Publication::read answers None and every entity’s documentation is null.
The declaration is the small TOML subset the site generator reads with awk: #
comment lines, one [[kinds]] table per kind, and key = value lines whose string
values are double-quoted. Anything else is ignored rather than guessed at, exactly as
the generator ignores it.
use majordomus_cli::entity::Publication;
let p = Publication::parse(
"[[kinds]]\nkind = \"adr\"\nprojection = \"entity\"\nroute = \"/adrs/\"\n",
Some("base_url = \"https://example.invalid\"\n"),
);
assert_eq!(p.kinds.len(), 1);
assert_eq!(p.base_url.as_deref(), Some("https://example.invalid"));
// with no site configuration, the routes stand and no URL is invented
assert_eq!(Publication::parse("", None), Publication::default());Fields§
§kinds: Vec<PublishedKind>Every declared kind, in the file’s order.
base_url: Option<String>The site’s base_url without a trailing slash, when the site configuration has one.
Implementations§
Source§impl Publication
impl Publication
Sourcepub fn parse(declaration: &str, site_config: Option<&str>) -> Publication
pub fn parse(declaration: &str, site_config: Option<&str>) -> Publication
Parse a publication declaration and, when there is one, the site configuration its
base_url is read from (a top-level key, before the first table).
use majordomus_cli::entity::Publication;
let p = Publication::parse(
"# comment\n[[kinds]]\nkind = \"prompt\"\nprojection = \"none\"\nreason = \"a \\\"why\\\"\"\n",
Some("base_url = \"https://example.invalid/\"\n[markdown]\nbase_url = \"no\"\n"),
);
assert_eq!(p.base_url.as_deref(), Some("https://example.invalid"));
assert_eq!(p.kind("prompt").unwrap().reason.as_deref(), Some("a \"why\""));Sourcepub fn read(root: &Path) -> Option<Publication>
pub fn read(root: &Path) -> Option<Publication>
Read the declaration of the repository at root, or None when it has none.
use majordomus_cli::entity::{Publication, PUBLICATION};
let root = std::env::temp_dir().join(format!("mj-publication-{}", std::process::id()));
// a repository with no site declares nothing, and nothing is invented for it
assert!(Publication::read(&root.join("absent")).is_none());
std::fs::create_dir_all(root.join("site/data")).unwrap();
std::fs::write(
root.join(PUBLICATION),
"[[kinds]]\nkind = \"adr\"\nprojection = \"entity\"\nroute = \"/adrs/\"\n",
)
.unwrap();
let p = Publication::read(&root).unwrap();
assert_eq!(p.kinds.len(), 1);
assert_eq!(p.base_url, None, "no site/config.toml, so no base URL");
std::fs::remove_dir_all(&root).unwrap();Sourcepub fn kind(&self, kind: &str) -> Option<&PublishedKind>
pub fn kind(&self, kind: &str) -> Option<&PublishedKind>
The declaration of one kind, if the file declares it.
use majordomus_cli::entity::Publication;
let p = Publication::parse(
"[[kinds]]\nkind = \"prompt\"\nprojection = \"none\"\nreason = \"internal\"\n",
None,
);
assert_eq!(p.kind("prompt").and_then(|k| k.reason.as_deref()), Some("internal"));
assert!(p.kind("adr").is_none());Sourcepub fn documentation(&self, kind: &str, slug: &str) -> Option<Documentation>
pub fn documentation(&self, kind: &str, slug: &str) -> Option<Documentation>
The public page of the entity slug of kind: the same function
scripts/generate-site-data writes the site’s pages with — route + slug + / for
an entity kind, the kind’s route for a section kind, nothing for none. A kind
the declaration does not name has no answer, because nothing decided it.
use majordomus_cli::entity::Publication;
let p = Publication::parse(
"[[kinds]]\nkind = \"adr\"\nprojection = \"entity\"\nroute = \"/adrs/\"\n\
[[kinds]]\nkind = \"skill\"\nprojection = \"section\"\nroute = \"/skills/\"\n",
Some("base_url = \"https://example.invalid\"\n"),
);
let adr = p.documentation("adr", "adr-0056").unwrap();
assert_eq!(adr.url.as_deref(), Some("https://example.invalid/adrs/adr-0056/"));
let skill = p.documentation("skill", "commit").unwrap();
assert_eq!(skill.route.as_deref(), Some("/skills/"));
assert!(p.documentation("prompt", "x").is_none());Trait Implementations§
Source§impl Clone for Publication
impl Clone for Publication
Source§fn clone(&self) -> Publication
fn clone(&self) -> Publication
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Publication
impl Debug for Publication
Source§impl Default for Publication
impl Default for Publication
Source§fn default() -> Publication
fn default() -> Publication
impl Eq for Publication
Source§impl PartialEq for Publication
impl PartialEq for Publication
Source§fn eq(&self, other: &Publication) -> bool
fn eq(&self, other: &Publication) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for Publication
Auto Trait Implementations§
impl Freeze for Publication
impl RefUnwindSafe for Publication
impl Send for Publication
impl Sync for Publication
impl Unpin for Publication
impl UnsafeUnpin for Publication
impl UnwindSafe for Publication
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.