Browse Source

Generate per language RSS feed

index-subcmd
Vincent Prouillet 5 years ago
parent
commit
3d22b4f1f9
9 changed files with 65 additions and 7 deletions
  1. +1
    -0
      .gitignore
  2. +1
    -1
      components/config/src/config.rs
  3. +1
    -1
      components/library/src/content/file_info.rs
  4. +33
    -1
      components/site/src/lib.rs
  5. +1
    -1
      components/site/tests/common.rs
  6. +13
    -2
      components/site/tests/site_i18n.rs
  7. +4
    -1
      test_site_i18n/config.toml
  8. +4
    -0
      test_site_i18n/content/blog/_index.it.md
  9. +7
    -0
      test_site_i18n/content/blog/fixed-slug.it.md

+ 1
- 0
.gitignore View File

@@ -14,6 +14,7 @@ huge-kb


current.bench current.bench
now.bench now.bench
*.zst


# snapcraft artifacts # snapcraft artifacts
snap/.snapcraft snap/.snapcraft


+ 1
- 1
components/config/src/config.rs View File

@@ -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()
} }




+ 1
- 1
components/library/src/content/file_info.rs View File

@@ -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);
} }




+ 33
- 1
components/site/src/lib.rs View File

@@ -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()?;


+ 1
- 1
components/site/tests/common.rs View File

@@ -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
- 2
components/site/tests/site_i18n.rs View File

@@ -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.sections().len(), 4);
assert_eq!(site.library.pages().len(), 10);
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"));
} }

+ 4
- 1
test_site_i18n/config.toml View File

@@ -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
- 0
test_site_i18n/content/blog/_index.it.md View File

@@ -0,0 +1,4 @@
+++
sort_by = "date"
insert_anchors = "right"
+++

+ 7
- 0
test_site_i18n/content/blog/fixed-slug.it.md View 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…
Cancel
Save