Skip to content

Commit 58684e3

Browse files
authored
Strip only overlapping prefix (#69)
* skip only node_modules * Strip only overlapping prefix
1 parent fb94088 commit 58684e3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,22 @@ pub fn process_transform(program: Program, _metadata: TransformPluginProgramMeta
4242
let cwd = &raw_cwd.replace('\\', "/");
4343
let path = &raw_path.replace('\\', "/");
4444

45-
if let Some(relative_path) = path.strip_prefix(cwd) {
45+
// overlapping prefix
46+
let prefix = cwd
47+
.chars()
48+
.zip(path.chars())
49+
.take_while(|(a, b)| a == b)
50+
.map(|(a, _)| a)
51+
.collect::<String>();
52+
53+
if let Some(relative_path) = path.strip_prefix(&prefix) {
4654
let mut is_page = false;
4755

4856
for component in Path::new(relative_path).components() {
4957
match component {
5058
Component::Normal(str) => match str.to_str().unwrap_or_default() {
5159
// skip non-source stuff
52-
"node_modules" | "dist" => {
60+
"node_modules" => {
5361
return program;
5462
}
5563
"pages" => {

0 commit comments

Comments
 (0)