Skip to main content

Publication

Struct Publication 

Source
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

Source

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\""));
Source

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();
Source

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());
Source

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

Source§

fn clone(&self) -> Publication

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Publication

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Publication

Source§

fn default() -> Publication

Returns the “default value” for a type. Read more
Source§

impl Eq for Publication

Source§

impl PartialEq for Publication

Source§

fn eq(&self, other: &Publication) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Publication

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more