File tree Expand file tree Collapse file tree 3 files changed +19
-0
lines changed Expand file tree Collapse file tree 3 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -210,6 +210,12 @@ The following configuration options are available:
210
210
- ** site-url:** The url where the book will be hosted. This is required to ensure
211
211
navigation links and script/css imports in the 404 file work correctly, even when accessing
212
212
urls in subdirectories. Defaults to ` / ` .
213
+ - ** cname:** The DNS subdomain or apex domain at which your book will be hosted.
214
+ This string will be written to a file named CNAME in the root of your site, as
215
+ required by GitHub Pages (see [ * Managing a custom domain for your GitHub Pages
216
+ site* ] [ custom domain ] ).
217
+
218
+ [ custom domain ] : https://docs.github.com/en/github/working-with-github-pages/managing-a-custom-domain-for-your-github-pages-site
213
219
214
220
Available configuration options for the ` [output.html.fold] ` table:
215
221
@@ -273,6 +279,7 @@ no-section-label = false
273
279
git-repository-url = " https://github.com/rust-lang/mdBook"
274
280
git-repository-icon = " fa-github"
275
281
site-url = " /example-book/"
282
+ cname = " myproject.rs"
276
283
input-404 = " not-found.md"
277
284
278
285
[output .html .fold ]
Original file line number Diff line number Diff line change @@ -508,6 +508,13 @@ pub struct HtmlConfig {
508
508
pub input_404 : Option < String > ,
509
509
/// Absolute url to site, used to emit correct paths for the 404 page, which might be accessed in a deeply nested directory
510
510
pub site_url : Option < String > ,
511
+ /// The DNS subdomain or apex domain at which your book will be hosted. This
512
+ /// string will be written to a file named CNAME in the root of your site,
513
+ /// as required by GitHub Pages (see [*Managing a custom domain for your
514
+ /// GitHub Pages site*][custom domain]).
515
+ ///
516
+ /// [custom domain]: https://docs.github.com/en/github/working-with-github-pages/managing-a-custom-domain-for-your-github-pages-site
517
+ pub cname : Option < String > ,
511
518
/// This is used as a bit of a workaround for the `mdbook serve` command.
512
519
/// Basically, because you set the websocket port from the command line, the
513
520
/// `mdbook serve` command needs a way to let the HTML renderer know where
@@ -541,6 +548,7 @@ impl Default for HtmlConfig {
541
548
git_repository_icon : None ,
542
549
input_404 : None ,
543
550
site_url : None ,
551
+ cname : None ,
544
552
livereload_url : None ,
545
553
redirect : HashMap :: new ( ) ,
546
554
}
Original file line number Diff line number Diff line change @@ -187,6 +187,10 @@ impl HtmlHandlebars {
187
187
b"This file makes sure that Github Pages doesn't process mdBook's output." ,
188
188
) ?;
189
189
190
+ if let Some ( cname) = & html_config. cname {
191
+ write_file ( destination, "CNAME" , format ! ( "{}\n " , cname) . as_bytes ( ) ) ?;
192
+ }
193
+
190
194
write_file ( destination, "book.js" , & theme. js ) ?;
191
195
write_file ( destination, "css/general.css" , & theme. general_css ) ?;
192
196
write_file ( destination, "css/chrome.css" , & theme. chrome_css ) ?;
You can’t perform that action at this time.
0 commit comments