-
Notifications
You must be signed in to change notification settings - Fork 909
/
mod.rs
767 lines (667 loc) · 24.8 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
pub mod languages;
pub mod link_checker;
pub mod markup;
pub mod search;
pub mod slugify;
pub mod taxonomies;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use libs::globset::{Glob, GlobSet, GlobSetBuilder};
use libs::toml::Value as Toml;
use serde::{Deserialize, Serialize};
use crate::theme::Theme;
use errors::{anyhow, bail, Result};
use utils::fs::read_file;
use utils::slugs::slugify_paths;
// We want a default base url for tests
static DEFAULT_BASE_URL: &str = "http://a-website.com";
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Mode {
Build,
Serve,
Check,
}
#[derive(Clone, Debug, Deserialize)]
#[serde(default)]
pub struct Config {
/// Base URL of the site, the only required config argument
pub base_url: String,
/// Theme to use
pub theme: Option<String>,
/// Title of the site. Defaults to None
pub title: Option<String>,
/// Description of the site
pub description: Option<String>,
/// The language used in the site. Defaults to "en"
pub default_language: String,
/// The list of supported languages outside of the default one
pub languages: HashMap<String, languages::LanguageOptions>,
/// The translations strings for the default language
translations: HashMap<String, String>,
/// Whether to generate a feed. Defaults to false.
pub generate_feed: bool,
/// The number of articles to include in the feed. Defaults to including all items.
pub feed_limit: Option<usize>,
/// The filename to use for feeds. Used to find the template, too.
/// Defaults to "atom.xml", with "rss.xml" also having a template provided out of the box.
pub feed_filename: String,
/// If set, files from static/ will be hardlinked instead of copied to the output dir.
pub hard_link_static: bool,
pub taxonomies: Vec<taxonomies::TaxonomyConfig>,
/// Whether to compile the `sass` directory and output the css files into the static folder
pub compile_sass: bool,
/// Whether to minify the html output
pub minify_html: bool,
/// Whether to build the search index for the content
pub build_search_index: bool,
/// A list of file glob patterns to ignore when processing the content folder. Defaults to none.
/// Had to remove the PartialEq derive because GlobSet does not implement it. No impact
/// because it's unused anyway (who wants to sort Configs?).
pub ignored_content: Vec<String>,
#[serde(skip_serializing, skip_deserializing)] // not a typo, 2 are needed
pub ignored_content_globset: Option<GlobSet>,
/// The mode Zola is currently being ran on. Some logging/feature can differ depending on the
/// command being used.
#[serde(skip_serializing)]
pub mode: Mode,
pub output_dir: String,
pub link_checker: link_checker::LinkChecker,
/// The setup for which slugification strategies to use for paths, taxonomies and anchors
pub slugify: slugify::Slugify,
/// The search config, telling what to include in the search index
pub search: search::Search,
/// The config for the Markdown rendering: syntax highlighting and everything
pub markdown: markup::Markdown,
/// All user params set in `[extra]` in the config
pub extra: HashMap<String, Toml>,
}
#[derive(Serialize)]
pub struct SerializedConfig<'a> {
base_url: &'a str,
mode: Mode,
title: &'a Option<String>,
description: &'a Option<String>,
languages: HashMap<&'a String, &'a languages::LanguageOptions>,
default_language: &'a str,
generate_feed: bool,
feed_filename: &'a str,
taxonomies: &'a [taxonomies::TaxonomyConfig],
build_search_index: bool,
extra: &'a HashMap<String, Toml>,
}
impl Config {
// any extra syntax and highlight themes have been loaded and validated already by the from_file method before parsing the config
/// Parses a string containing TOML to our Config struct
/// Any extra parameter will end up in the extra field
pub fn parse(content: &str) -> Result<Config> {
let mut config: Config = match libs::toml::from_str(content) {
Ok(c) => c,
Err(e) => bail!(e),
};
if config.base_url.is_empty() || config.base_url == DEFAULT_BASE_URL {
bail!("A base URL is required in config.toml with key `base_url`");
}
languages::validate_code(&config.default_language)?;
for code in config.languages.keys() {
languages::validate_code(code)?;
}
config.add_default_language();
config.slugify_taxonomies();
if !config.ignored_content.is_empty() {
// Convert the file glob strings into a compiled glob set matcher. We want to do this once,
// at program initialization, rather than for every page, for example. We arrange for the
// globset matcher to always exist (even though it has to be an inside an Option at the
// moment because of the TOML serializer); if the glob set is empty the `is_match` function
// of the globber always returns false.
let mut glob_set_builder = GlobSetBuilder::new();
for pat in &config.ignored_content {
let glob = match Glob::new(pat) {
Ok(g) => g,
Err(e) => bail!("Invalid ignored_content glob pattern: {}, error = {}", pat, e),
};
glob_set_builder.add(glob);
}
config.ignored_content_globset =
Some(glob_set_builder.build().expect("Bad ignored_content in config file."));
}
Ok(config)
}
pub fn default_for_test() -> Self {
let mut config = Config::default();
config.add_default_language();
config.slugify_taxonomies();
config
}
/// Parses a config file from the given path
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Config> {
let path = path.as_ref();
let content = read_file(path)?;
let mut config = Config::parse(&content)?;
let config_dir = path
.parent()
.ok_or_else(|| anyhow!("Failed to find directory containing the config file."))?;
// this is the step at which missing extra syntax and highlighting themes are raised as errors
config.markdown.init_extra_syntaxes_and_highlight_themes(config_dir)?;
Ok(config)
}
pub fn slugify_taxonomies(&mut self) {
for (_, lang_options) in self.languages.iter_mut() {
for tax_def in lang_options.taxonomies.iter_mut() {
tax_def.slug = slugify_paths(&tax_def.name, self.slugify.taxonomies);
}
}
}
/// Makes a url, taking into account that the base url might have a trailing slash
pub fn make_permalink(&self, path: &str) -> String {
let trailing_bit =
if path.ends_with('/') || path.ends_with(&self.feed_filename) || path.is_empty() {
""
} else {
"/"
};
// Index section with a base url that has a trailing slash
if self.base_url.ends_with('/') && path == "/" {
self.base_url.clone()
} else if path == "/" {
// index section with a base url that doesn't have a trailing slash
format!("{}/", self.base_url)
} else if self.base_url.ends_with('/') && path.starts_with('/') {
format!("{}{}{}", self.base_url, &path[1..], trailing_bit)
} else if self.base_url.ends_with('/') || path.starts_with('/') {
format!("{}{}{}", self.base_url, path, trailing_bit)
} else {
format!("{}/{}{}", self.base_url, path, trailing_bit)
}
}
/// Adds the default language to the list of languages if not present
pub fn add_default_language(&mut self) {
// We automatically insert a language option for the default language *if* it isn't present
// TODO: what to do if there is like an empty dict for the lang? merge it or use the language
// TODO: as source of truth?
if !self.languages.contains_key(&self.default_language) {
self.languages.insert(
self.default_language.clone(),
languages::LanguageOptions {
title: self.title.clone(),
description: self.description.clone(),
generate_feed: self.generate_feed,
feed_filename: self.feed_filename.clone(),
build_search_index: self.build_search_index,
taxonomies: self.taxonomies.clone(),
search: self.search.clone(),
translations: self.translations.clone(),
},
);
}
}
/// Merges the extra data from the theme with the config extra data
fn add_theme_extra(&mut self, theme: &Theme) -> Result<()> {
for (key, val) in &theme.extra {
if !self.extra.contains_key(key) {
// The key is not overridden in site config, insert it
self.extra.insert(key.to_string(), val.clone());
continue;
}
merge(self.extra.get_mut(key).unwrap(), val)?;
}
Ok(())
}
/// Parse the theme.toml file and merges the extra data from the theme
/// with the config extra data
pub fn merge_with_theme(&mut self, path: PathBuf, theme_name: &str) -> Result<()> {
let theme = Theme::from_file(&path, theme_name)?;
self.add_theme_extra(&theme)
}
/// Returns all the languages settings for languages other than the default one
pub fn other_languages(&self) -> HashMap<&str, &languages::LanguageOptions> {
let mut others = HashMap::new();
for (k, v) in &self.languages {
if k == &self.default_language {
continue;
}
others.insert(k.as_str(), v);
}
others
}
pub fn other_languages_codes(&self) -> Vec<&str> {
self.languages.keys().filter(|k| *k != &self.default_language).map(|k| k.as_str()).collect()
}
/// Is this site using i18n?
pub fn is_multilingual(&self) -> bool {
!self.other_languages().is_empty()
}
pub fn is_in_check_mode(&self) -> bool {
self.mode == Mode::Check
}
pub fn enable_serve_mode(&mut self) {
self.mode = Mode::Serve;
}
pub fn enable_check_mode(&mut self) {
self.mode = Mode::Check;
// Disable syntax highlighting since the results won't be used and it is slow
self.markdown.highlight_code = false;
}
pub fn get_translation(&self, lang: &str, key: &str) -> Result<String> {
if let Some(options) = self.languages.get(lang) {
options
.translations
.get(key)
.ok_or_else(|| {
anyhow!("Translation key '{}' for language '{}' is missing", key, lang)
})
.map(|term| term.to_string())
} else {
bail!("Language '{}' not found.", lang)
}
}
pub fn has_taxonomy(&self, name: &str, lang: &str) -> bool {
if let Some(lang_options) = self.languages.get(lang) {
lang_options.taxonomies.iter().any(|t| t.name == name)
} else {
false
}
}
pub fn serialize(&self, lang: &str) -> SerializedConfig {
let options = &self.languages[lang];
SerializedConfig {
base_url: &self.base_url,
mode: self.mode,
title: &options.title,
description: &options.description,
languages: self.languages.iter().filter(|(k, _)| k.as_str() != lang).collect(),
default_language: &self.default_language,
generate_feed: options.generate_feed,
feed_filename: &options.feed_filename,
taxonomies: &options.taxonomies,
build_search_index: options.build_search_index,
extra: &self.extra,
}
}
}
// merge TOML data that can be a table, or anything else
pub fn merge(into: &mut Toml, from: &Toml) -> Result<()> {
match (from.is_table(), into.is_table()) {
(false, false) => {
// These are not tables so we have nothing to merge
Ok(())
}
(true, true) => {
// Recursively merge these tables
let into_table = into.as_table_mut().unwrap();
for (key, val) in from.as_table().unwrap() {
if !into_table.contains_key(key) {
// An entry was missing in the first table, insert it
into_table.insert(key.to_string(), val.clone());
continue;
}
// Two entries to compare, recurse
merge(into_table.get_mut(key).unwrap(), val)?;
}
Ok(())
}
_ => {
// Trying to merge a table with something else
Err(anyhow!("Cannot merge config.toml with theme.toml because the following values have incompatibles types:\n- {}\n - {}", into, from))
}
}
}
impl Default for Config {
fn default() -> Config {
Config {
base_url: DEFAULT_BASE_URL.to_string(),
title: None,
description: None,
theme: None,
default_language: "en".to_string(),
languages: HashMap::new(),
generate_feed: false,
feed_limit: None,
feed_filename: "atom.xml".to_string(),
hard_link_static: false,
taxonomies: Vec::new(),
compile_sass: false,
minify_html: false,
mode: Mode::Build,
build_search_index: false,
ignored_content: Vec::new(),
ignored_content_globset: None,
translations: HashMap::new(),
output_dir: "public".to_string(),
link_checker: link_checker::LinkChecker::default(),
slugify: slugify::Slugify::default(),
search: search::Search::default(),
markdown: markup::Markdown::default(),
extra: HashMap::new(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use utils::slugs::SlugifyStrategy;
#[test]
fn can_import_valid_config() {
let config = r#"
title = "My site"
base_url = "https://replace-this-with-your-url.com"
"#;
let config = Config::parse(config).unwrap();
assert_eq!(config.title.unwrap(), "My site".to_string());
}
#[test]
fn errors_when_invalid_type() {
let config = r#"
title = 1
base_url = "https://replace-this-with-your-url.com"
"#;
let config = Config::parse(config);
assert!(config.is_err());
}
#[test]
fn errors_when_missing_required_field() {
// base_url is required
let config = r#"
title = ""
"#;
let config = Config::parse(config);
assert!(config.is_err());
}
#[test]
fn can_add_extra_values() {
let config = r#"
title = "My site"
base_url = "https://replace-this-with-your-url.com"
[extra]
hello = "world"
"#;
let config = Config::parse(config);
assert!(config.is_ok());
assert_eq!(config.unwrap().extra.get("hello").unwrap().as_str().unwrap(), "world");
}
#[test]
fn can_make_url_index_page_with_non_trailing_slash_url() {
let config = Config { base_url: "http://vincent.is".to_string(), ..Default::default() };
assert_eq!(config.make_permalink(""), "http://vincent.is/");
}
#[test]
fn can_make_url_index_page_with_railing_slash_url() {
let config = Config { base_url: "http://vincent.is".to_string(), ..Default::default() };
assert_eq!(config.make_permalink(""), "http://vincent.is/");
}
#[test]
fn can_make_url_with_non_trailing_slash_base_url() {
let config = Config { base_url: "http://vincent.is".to_string(), ..Default::default() };
assert_eq!(config.make_permalink("hello"), "http://vincent.is/hello/");
}
#[test]
fn can_make_url_with_trailing_slash_path() {
let config = Config { base_url: "http://vincent.is".to_string(), ..Default::default() };
assert_eq!(config.make_permalink("/hello"), "http://vincent.is/hello/");
}
#[test]
fn can_make_url_with_localhost() {
let config = Config { base_url: "http://127.0.0.1:1111".to_string(), ..Default::default() };
assert_eq!(config.make_permalink("/tags/rust"), "http://127.0.0.1:1111/tags/rust/");
}
// https://github.com/Keats/gutenberg/issues/486
#[test]
fn doesnt_add_trailing_slash_to_feed() {
let config = Config { base_url: "http://vincent.is".to_string(), ..Default::default() };
assert_eq!(config.make_permalink("atom.xml"), "http://vincent.is/atom.xml");
}
#[test]
fn can_merge_with_theme_data_and_preserve_config_value() {
let config_str = r#"
title = "My site"
base_url = "https://replace-this-with-your-url.com"
[extra]
hello = "world"
[extra.sub]
foo = "bar"
[extra.sub.sub]
foo = "bar"
"#;
let mut config = Config::parse(config_str).unwrap();
let theme_str = r#"
[extra]
hello = "foo"
a_value = 10
[extra.sub]
foo = "default"
truc = "default"
[extra.sub.sub]
foo = "default"
truc = "default"
"#;
let theme = Theme::parse(theme_str).unwrap();
assert!(config.add_theme_extra(&theme).is_ok());
let extra = config.extra;
assert_eq!(extra["hello"].as_str().unwrap(), "world".to_string());
assert_eq!(extra["a_value"].as_integer().unwrap(), 10);
assert_eq!(extra["sub"]["foo"].as_str().unwrap(), "bar".to_string());
assert_eq!(extra["sub"].get("truc").expect("The whole extra.sub table was overridden by theme data, discarding extra.sub.truc").as_str().unwrap(), "default".to_string());
assert_eq!(extra["sub"]["sub"]["foo"].as_str().unwrap(), "bar".to_string());
assert_eq!(
extra["sub"]["sub"]
.get("truc")
.expect("Failed to merge subsubtable extra.sub.sub")
.as_str()
.unwrap(),
"default".to_string()
);
}
const CONFIG_TRANSLATION: &str = r#"
base_url = "https://remplace-par-ton-url.fr"
default_language = "fr"
[translations]
title = "Un titre"
[languages.en]
[languages.en.translations]
title = "A title"
"#;
#[test]
fn can_use_present_translation() {
let config = Config::parse(CONFIG_TRANSLATION).unwrap();
assert!(config.languages.contains_key("fr"));
assert_eq!(config.get_translation("fr", "title").unwrap(), "Un titre");
assert_eq!(config.get_translation("en", "title").unwrap(), "A title");
}
#[test]
fn error_on_absent_translation_lang() {
let config = Config::parse(CONFIG_TRANSLATION).unwrap();
let error = config.get_translation("absent", "key").unwrap_err();
assert_eq!("Language 'absent' not found.", format!("{}", error));
}
#[test]
fn error_on_absent_translation_key() {
let config = Config::parse(CONFIG_TRANSLATION).unwrap();
let error = config.get_translation("en", "absent").unwrap_err();
assert_eq!("Translation key 'absent' for language 'en' is missing", format!("{}", error));
}
#[test]
fn missing_ignored_content_results_in_empty_vector_and_empty_globset() {
let config_str = r#"
title = "My site"
base_url = "example.com"
"#;
let config = Config::parse(config_str).unwrap();
let v = config.ignored_content;
assert_eq!(v.len(), 0);
assert!(config.ignored_content_globset.is_none());
}
#[test]
fn empty_ignored_content_results_in_empty_vector_and_empty_globset() {
let config_str = r#"
title = "My site"
base_url = "example.com"
ignored_content = []
"#;
let config = Config::parse(config_str).unwrap();
assert_eq!(config.ignored_content.len(), 0);
assert!(config.ignored_content_globset.is_none());
}
#[test]
fn non_empty_ignored_content_results_in_vector_of_patterns_and_configured_globset() {
let config_str = r#"
title = "My site"
base_url = "example.com"
ignored_content = ["*.{graphml,iso}", "*.py?", "**/{target,temp_folder}"]
"#;
let config = Config::parse(config_str).unwrap();
let v = config.ignored_content;
assert_eq!(v, vec!["*.{graphml,iso}", "*.py?", "**/{target,temp_folder}"]);
let g = config.ignored_content_globset.unwrap();
assert_eq!(g.len(), 3);
assert!(g.is_match("foo.graphml"));
assert!(g.is_match("foo/bar/foo.graphml"));
assert!(g.is_match("foo.iso"));
assert!(!g.is_match("foo.png"));
assert!(g.is_match("foo.py2"));
assert!(g.is_match("foo.py3"));
assert!(!g.is_match("foo.py"));
assert!(g.is_match("foo/bar/target"));
assert!(g.is_match("foo/bar/baz/temp_folder"));
assert!(g.is_match("foo/bar/baz/temp_folder/target"));
assert!(g.is_match("temp_folder"));
assert!(g.is_match("my/isos/foo.iso"));
assert!(g.is_match("content/poetry/zen.py2"));
}
#[test]
fn link_checker_skip_anchor_prefixes() {
let config_str = r#"
title = "My site"
base_url = "example.com"
[link_checker]
skip_anchor_prefixes = [
"https://caniuse.com/#feat=",
"https://github.com/rust-lang/rust/blob/",
]
"#;
let config = Config::parse(config_str).unwrap();
assert_eq!(
config.link_checker.skip_anchor_prefixes,
vec!["https://caniuse.com/#feat=", "https://github.com/rust-lang/rust/blob/"]
);
}
#[test]
fn link_checker_skip_prefixes() {
let config_str = r#"
title = "My site"
base_url = "example.com"
[link_checker]
skip_prefixes = [
"http://[2001:db8::]/",
"https://www.example.com/path",
]
"#;
let config = Config::parse(config_str).unwrap();
assert_eq!(
config.link_checker.skip_prefixes,
vec!["http://[2001:db8::]/", "https://www.example.com/path",]
);
}
#[test]
fn slugify_strategies() {
let config_str = r#"
title = "My site"
base_url = "example.com"
[slugify]
paths = "on"
taxonomies = "safe"
anchors = "off"
"#;
let config = Config::parse(config_str).unwrap();
assert_eq!(config.slugify.paths, SlugifyStrategy::On);
assert_eq!(config.slugify.paths_keep_dates, false);
assert_eq!(config.slugify.taxonomies, SlugifyStrategy::Safe);
assert_eq!(config.slugify.anchors, SlugifyStrategy::Off);
}
#[test]
fn slugify_paths_keep_dates() {
let config_str = r#"
title = "My site"
base_url = "example.com"
[slugify]
paths_keep_dates = true
taxonomies = "off"
anchors = "safe"
"#;
let config = Config::parse(config_str).unwrap();
assert_eq!(config.slugify.paths, SlugifyStrategy::On);
assert_eq!(config.slugify.paths_keep_dates, true);
assert_eq!(config.slugify.taxonomies, SlugifyStrategy::Off);
assert_eq!(config.slugify.anchors, SlugifyStrategy::Safe);
}
#[test]
fn cannot_overwrite_theme_mapping_with_invalid_type() {
let config_str = r#"
base_url = "http://localhost:1312"
default_language = "fr"
[extra]
foo = "bar"
"#;
let mut config = Config::parse(config_str).unwrap();
let theme_str = r#"
[extra]
[extra.foo]
bar = "baz"
"#;
let theme = Theme::parse(theme_str).unwrap();
// We expect an error here
assert!(config.add_theme_extra(&theme).is_err());
}
#[test]
fn default_output_dir() {
let config = r#"
title = "My site"
base_url = "https://replace-this-with-your-url.com"
"#;
let config = Config::parse(config).unwrap();
assert_eq!(config.output_dir, "public".to_string());
}
#[test]
fn can_add_output_dir() {
let config = r#"
title = "My site"
base_url = "https://replace-this-with-your-url.com"
output_dir = "docs"
"#;
let config = Config::parse(config).unwrap();
assert_eq!(config.output_dir, "docs".to_string());
}
// TODO: Tests for valid themes; need extra scaffolding (test site) for custom themes.
#[test]
fn invalid_highlight_theme() {
let config = r#"
[markup]
highlight_code = true
highlight_theme = "asdf"
"#;
let config = Config::parse(config);
assert!(config.is_err());
}
#[test]
fn invalid_highlight_theme_css_export() {
let config = r#"
[markup]
highlight_code = true
highlight_themes_css = [
{ theme = "asdf", filename = "asdf.css" },
]
"#;
let config = Config::parse(config);
assert!(config.is_err());
}
// https://github.com/getzola/zola/issues/1687
#[test]
fn regression_config_default_lang_data() {
let config = r#"
base_url = "https://www.getzola.org/"
title = "Zola"
"#;
let config = Config::parse(config).unwrap();
let serialised = config.serialize(&config.default_language);
assert_eq!(serialised.title, &config.title);
}
}