Generate per language RSS feed
This commit is contained in:
parent
832360f9b1
commit
3d22b4f1f9
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -14,6 +14,7 @@ huge-kb
|
||||||
|
|
||||||
current.bench
|
current.bench
|
||||||
now.bench
|
now.bench
|
||||||
|
*.zst
|
||||||
|
|
||||||
# snapcraft artifacts
|
# snapcraft artifacts
|
||||||
snap/.snapcraft
|
snap/.snapcraft
|
||||||
|
|
|
@ -246,7 +246,7 @@ impl Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is this site using i18n?
|
/// Is this site using i18n?
|
||||||
pub fn uses_i18n(&self) -> bool {
|
pub fn is_multilingual(&self) -> bool {
|
||||||
!self.languages.is_empty()
|
!self.languages.is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,7 @@ impl FileInfo {
|
||||||
/// remove it and return the language code
|
/// remove it and return the language code
|
||||||
pub fn find_language(&mut self, config: &Config) -> Result<Option<String>> {
|
pub fn find_language(&mut self, config: &Config) -> Result<Option<String>> {
|
||||||
// No languages? Nothing to do
|
// No languages? Nothing to do
|
||||||
if !config.uses_i18n() {
|
if !config.is_multilingual() {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -511,9 +511,41 @@ impl Site {
|
||||||
self.render_sections()?;
|
self.render_sections()?;
|
||||||
self.render_orphan_pages()?;
|
self.render_orphan_pages()?;
|
||||||
self.render_sitemap()?;
|
self.render_sitemap()?;
|
||||||
|
|
||||||
if self.config.generate_rss {
|
if self.config.generate_rss {
|
||||||
self.render_rss_feed(self.library.pages_values(), None)?;
|
let pages = if self.config.is_multilingual() {
|
||||||
|
self.library
|
||||||
|
.pages_values()
|
||||||
|
.iter()
|
||||||
|
.filter(|p| p.lang.is_none())
|
||||||
|
.map(|p| *p)
|
||||||
|
.collect()
|
||||||
|
} else {
|
||||||
|
self.library.pages_values()
|
||||||
|
};
|
||||||
|
self.render_rss_feed(pages, None)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for lang in &self.config.languages {
|
||||||
|
if !lang.rss {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let pages = self
|
||||||
|
.library
|
||||||
|
.pages_values()
|
||||||
|
.iter()
|
||||||
|
.filter(|p| {
|
||||||
|
if let Some(ref l) = p.lang {
|
||||||
|
l == &lang.code
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.map(|p| *p)
|
||||||
|
.collect();
|
||||||
|
self.render_rss_feed(pages, Some(&PathBuf::from(lang.code.clone())))?;
|
||||||
|
}
|
||||||
|
|
||||||
self.render_404()?;
|
self.render_404()?;
|
||||||
self.render_robots()?;
|
self.render_robots()?;
|
||||||
self.render_taxonomies()?;
|
self.render_taxonomies()?;
|
||||||
|
|
|
@ -30,7 +30,7 @@ macro_rules! file_contains {
|
||||||
let mut file = std::fs::File::open(&path).unwrap();
|
let mut file = std::fs::File::open(&path).unwrap();
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
file.read_to_string(&mut s).unwrap();
|
file.read_to_string(&mut s).unwrap();
|
||||||
println!("{}", s);
|
// println!("{}", s);
|
||||||
s.contains($text)
|
s.contains($text)
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@ fn can_parse_multilingual_site() {
|
||||||
let mut site = Site::new(&path, "config.toml").unwrap();
|
let mut site = Site::new(&path, "config.toml").unwrap();
|
||||||
site.load().unwrap();
|
site.load().unwrap();
|
||||||
|
|
||||||
assert_eq!(site.library.pages().len(), 9);
|
assert_eq!(site.library.pages().len(), 10);
|
||||||
assert_eq!(site.library.sections().len(), 4);
|
assert_eq!(site.library.sections().len(), 6);
|
||||||
|
|
||||||
// default index sections
|
// default index sections
|
||||||
let default_index_section =
|
let default_index_section =
|
||||||
|
@ -79,4 +79,15 @@ fn can_build_multilingual_site() {
|
||||||
assert!(file_exists!(public, "sitemap.xml"));
|
assert!(file_exists!(public, "sitemap.xml"));
|
||||||
assert!(file_contains!(public, "sitemap.xml", "https://example.com/blog/something-else/"));
|
assert!(file_contains!(public, "sitemap.xml", "https://example.com/blog/something-else/"));
|
||||||
assert!(file_contains!(public, "sitemap.xml", "https://example.com/fr/blog/something-else/"));
|
assert!(file_contains!(public, "sitemap.xml", "https://example.com/fr/blog/something-else/"));
|
||||||
|
assert!(file_contains!(public, "sitemap.xml", "https://example.com/it/blog/something-else/"));
|
||||||
|
|
||||||
|
// one rss per language
|
||||||
|
assert!(file_exists!(public, "rss.xml"));
|
||||||
|
assert!(file_contains!(public, "rss.xml", "https://example.com/blog/something-else/"));
|
||||||
|
assert!(!file_contains!(public, "rss.xml", "https://example.com/fr/blog/something-else/"));
|
||||||
|
assert!(file_exists!(public, "fr/rss.xml"));
|
||||||
|
assert!(!file_contains!(public, "fr/rss.xml", "https://example.com/blog/something-else/"));
|
||||||
|
assert!(file_contains!(public, "fr/rss.xml", "https://example.com/fr/blog/something-else/"));
|
||||||
|
// Italian doesn't have RSS enabled
|
||||||
|
assert!(!file_exists!(public, "it/rss.xml"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,11 @@ highlight_code = false
|
||||||
# Whether to build a search index to be used later on by a JavaScript library
|
# Whether to build a search index to be used later on by a JavaScript library
|
||||||
build_search_index = false
|
build_search_index = false
|
||||||
|
|
||||||
|
generate_rss = true
|
||||||
|
|
||||||
languages = [
|
languages = [
|
||||||
{code = "fr"},
|
{code = "fr", rss = true},
|
||||||
|
{code = "it", rss = false},
|
||||||
]
|
]
|
||||||
|
|
||||||
[extra]
|
[extra]
|
||||||
|
|
4
test_site_i18n/content/blog/_index.it.md
Normal file
4
test_site_i18n/content/blog/_index.it.md
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
+++
|
||||||
|
sort_by = "date"
|
||||||
|
insert_anchors = "right"
|
||||||
|
+++
|
7
test_site_i18n/content/blog/fixed-slug.it.md
Normal file
7
test_site_i18n/content/blog/fixed-slug.it.md
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
+++
|
||||||
|
title = "Un slug fixe"
|
||||||
|
slug = "something-else"
|
||||||
|
date = 2017-01-01
|
||||||
|
+++
|
||||||
|
|
||||||
|
Una pagina che definisce il suo slug nel front-matter
|
Loading…
Reference in a new issue