Browse Source

Ignore rename of non md files

index-subcmd
Vincent Prouillet 5 years ago
parent
commit
41a693a528
4 changed files with 19 additions and 1 deletions
  1. +7
    -0
      components/rebuild/src/lib.rs
  2. +11
    -0
      components/rebuild/tests/rebuild.rs
  3. +1
    -1
      test_site/content/posts/with-assets/index.md
  4. BIN
      test_site/content/posts/with-assets/zola.png

+ 7
- 0
components/rebuild/src/lib.rs View File

@@ -262,6 +262,13 @@ pub fn after_content_rename(site: &mut Site, old: &Path, new: &Path) -> Result<(
return site.build();
}

// We ignore renames on non-markdown files for now
if let Some(ext) = new_path.extension() {
if ext != "md" {
return Ok(());
}
}

// Renaming a file to _index.md, let the section editing do something and hope for the best
if new_path.file_name().unwrap() == "_index.md" {
// We aren't entirely sure where the original thing was so just try to delete whatever was


+ 11
- 0
components/rebuild/tests/rebuild.rs View File

@@ -223,3 +223,14 @@ fn can_rebuild_after_renaming_section_folder() {

assert!(file_contains!(site_path, "public/new-posts/simple/index.html", "simple"));
}

#[test]
fn can_rebuild_after_renaming_non_md_asset_in_colocated_folder() {
let tmp_dir = tempdir().expect("create temp dir");
let (site_path, mut site) = load_and_build_site!(tmp_dir);
let (old_path, new_path) = rename!(site_path, "content/posts/with-assets/zola.png", "gutenberg.png");

// Testing that we don't try to load some images as markdown or something
let res = after_content_rename(&mut site, &old_path, &new_path);
assert!(res.is_ok());
}

+ 1
- 1
test_site/content/posts/with-assets/index.md View File

@@ -4,4 +4,4 @@ description = "hey there"
date = 2015-03-01
+++

Hello world
Hello world [here](with.js)

BIN
test_site/content/posts/with-assets/zola.png View File

Before After
Width: 256  |  Height: 256  |  Size: 3.9KB

Loading…
Cancel
Save