abbaye/config.rs
1use std::path::PathBuf;
2
3use figment::{
4 Figment,
5 providers::{Format, Toml},
6};
7use miette::{IntoDiagnostic, Result};
8use serde::{Deserialize, Serialize};
9
10use schemars::JsonSchema;
11
12use crate::{
13 builders::BuilderEntry, changelog::ChangelogConfig, version_extractors::AnyVersionExtractor,
14};
15
16/// General website metadata.
17#[derive(Debug, Default, Clone, Deserialize, Serialize, JsonSchema)]
18pub struct SiteConfig {
19 /// Display name of the project, used in page titles and headings.
20 pub name: String,
21 /// Where to output generated files. Defaults to `public`.
22 #[serde(default = "abbaye_output_dir")]
23 pub output_dir: PathBuf,
24 /// Path to the README file rendered on each version page.
25 /// Defaults to `README.md` in the current working directory.
26 pub readme: Option<PathBuf>,
27 /// Canonical base URL of the published site (e.g. `"https://example.com"`).
28 /// When set, the generated `releases.atom` feed will include absolute links
29 /// and proper entry IDs. Trailing slashes are stripped automatically.
30 pub base_url: Option<String>,
31 /// URL of the project's repository (e.g. `"https://git.sr.ht/~ololduck/abbaye"`).
32 /// When set, we will show the repository link in the generated website.
33 pub repo_url: Option<String>,
34 /// An optional language code for the website (e.g. `"en"` or `"fr"`).
35 /// When set, the generated HTML will include a `lang` attribute on the `<html>` tag. Defaults to `"en"`.
36 pub lang: Option<String>,
37 /// If you have a Fediverse account, you can set this to your username to enable Fediverse integration. (don't forget the starting '@' !)
38 pub fediverse_creator: Option<String>,
39 /// OpenGraph configuration for the website.
40 pub opengraph: Option<OpenGraphConfig>,
41}
42
43/// OpenGraph configuration for the website.
44#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema)]
45pub struct OpenGraphConfig {
46 /// OpenGraph type of the website. It will be used as the `og:type` meta tag.
47 /// Note: by default, the value "website" will be enforced for the version listing page and "article" for the release notes page.
48 pub r#type: Option<String>,
49 /// URL of the website's image.
50 pub image: String,
51 /// Alt text for the website's image.
52 pub image_alt_text: Option<String>,
53 /// URL of the website. If not set, the `base_url` will be used instead. If `base_url` is not set either, the world explodes. Think of the kittens.
54 pub url: Option<String>,
55 /// Author of the website. Used on release notes pages to indicate the author.
56 pub author: Option<String>,
57}
58
59/// A full configuration for the Abbaye site generator.
60///
61/// Here's a sample configuration that works well as a starting point for rust projects:
62///
63/// ```toml
64/// [site]
65/// name = "Abbaye"
66///
67/// [version_extractor]
68/// type = "cargo" # extract version from Cargo.toml
69///
70/// [changelog]
71/// # let's use the default changelog extractor
72///
73/// [[builders]]
74/// type = "cargo" # calls `cargo build --release` for each target
75/// targets = ["x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl"]
76/// [[builders]]
77/// type = "cargo_doc" # generates documentation using `cargo doc`
78/// no_deps = true
79///
80/// [[builders]]
81/// type = "archive" # creates a compressed tarball of the source code
82/// ```
83///
84/// You can learn more about each builder type in the [builders module documentation](crate::builders).
85///
86#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema)]
87pub struct AbbayeConfig {
88 /// Metadata about the site.
89 pub site: SiteConfig,
90 /// which version extractor to use to extract the version(s) of the project
91 pub version_extractor: AnyVersionExtractor,
92 /// Configuration for the changelog extractor.
93 pub changelog: ChangelogConfig,
94 /// Builders to run during the build process.
95 pub builders: Vec<BuilderEntry>,
96}
97
98fn abbaye_output_dir() -> PathBuf {
99 PathBuf::from("public")
100}
101
102/// Load the Abbaye2 configuration from the current working directory.
103///
104/// Looks for `.abbaye.toml` first, then `abbaye.toml`; when both are present
105/// `abbaye.toml` takes precedence (last merge wins).
106pub fn load_config() -> Result<AbbayeConfig> {
107 let cwd = std::env::current_dir().into_diagnostic()?;
108 Figment::new()
109 .merge(Toml::file(cwd.join(".abbaye.toml")))
110 .merge(Toml::file(cwd.join("abbaye.toml")))
111 .merge(Toml::file(cwd.join(".abbaye").join("abbaye.toml")))
112 .extract()
113 .into_diagnostic()
114}