Skip to content

Commit

Permalink
Make filenames fuzzy-searchable
Browse files Browse the repository at this point in the history
I don't want a bunch of files coming up when I fuzzy search for "index".
Make it so using the same name within a folder equates to creating the
index for that folder.
  • Loading branch information
danott committed Jan 14, 2024
1 parent 5074a6d commit d036c07
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/build_paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ def source_path
end

def target_path
path
.sub(Build.source_dir, Build.target_dir)
.sub(".md", "/index.html")
.sub("/index/index.html", "/index.html")
extname = File.extname(path)
segments =
path
.sub(Build.source_dir, Build.target_dir)
.delete_suffix(extname)
.split("/")
segments.pop if segments.last(2).uniq.size == 1
segments.pop if segments.last == "index"
segments.push("index.html")
segments.join("/")
end

def url
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions test/build_paths_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@ def test_non_index_markdown_path
assert_equal("_site/path/to/another-thing/index.html", dummy.target_path)
assert_equal("/path/to/another-thing/", dummy.url)
end

def test_duplicate_identifier_path
dummy = Dummy.new("site/path/to/another-thing/another-thing.md")
assert_equal("site/path/to/another-thing/another-thing.md", dummy.path)
assert_equal(
"site/path/to/another-thing/another-thing.md",
dummy.source_path
)
assert_equal("_site/path/to/another-thing/index.html", dummy.target_path)
assert_equal("/path/to/another-thing/", dummy.url)
end
end

0 comments on commit d036c07

Please sign in to comment.