summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEric Huss <eric@huss.org>2020-09-06 09:21:29 -0700
committerGitHub <noreply@github.com>2020-09-06 09:21:29 -0700
commit1b18740b568b97a250f4588c1b060d199a3acff3 (patch)
treee4738f740dcd28f8dd5dde451be3383d1bc16fb9 /src
parent6fed9e52f9c6fca9c2f681f68e28878cfa44f638 (diff)
parent1acf23ff73c27ca0d2f0fd0dd256d7b175b2be27 (diff)
Merge pull request #1311 from dtolnay/cname
Support emitting CNAME file for publishing at a custom domain
Diffstat (limited to 'src')
-rw-r--r--src/config.rs8
-rw-r--r--src/renderer/html_handlebars/hbs_renderer.rs4
2 files changed, 12 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs
index 1389f139..ef6bc687 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -508,6 +508,13 @@ pub struct HtmlConfig {
pub input_404: Option<String>,
/// Absolute url to site, used to emit correct paths for the 404 page, which might be accessed in a deeply nested directory
pub site_url: Option<String>,
+ /// The DNS subdomain or apex domain at which your book will be hosted. This
+ /// string will be written to a file named CNAME in the root of your site,
+ /// as required by GitHub Pages (see [*Managing a custom domain for your
+ /// GitHub Pages site*][custom domain]).
+ ///
+ /// [custom domain]: https://docs.github.com/en/github/working-with-github-pages/managing-a-custom-domain-for-your-github-pages-site
+ pub cname: Option<String>,
/// This is used as a bit of a workaround for the `mdbook serve` command.
/// Basically, because you set the websocket port from the command line, the
/// `mdbook serve` command needs a way to let the HTML renderer know where
@@ -541,6 +548,7 @@ impl Default for HtmlConfig {
git_repository_icon: None,
input_404: None,
site_url: None,
+ cname: None,
livereload_url: None,
redirect: HashMap::new(),
}
diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs
index 7880817b..ec142eef 100644
--- a/src/renderer/html_handlebars/hbs_renderer.rs
+++ b/src/renderer/html_handlebars/hbs_renderer.rs
@@ -187,6 +187,10 @@ impl HtmlHandlebars {
b"This file makes sure that Github Pages doesn't process mdBook's output.",
)?;
+ if let Some(cname) = &html_config.cname {
+ write_file(destination, "CNAME", format!("{}\n", cname).as_bytes())?;
+ }
+
write_file(destination, "book.js", &theme.js)?;
write_file(destination, "css/general.css", &theme.general_css)?;
write_file(destination, "css/chrome.css", &theme.chrome_css)?;