Skip to content

Commit

Permalink
Refactor docs to use search_data.json instead of search-data.js
Browse files Browse the repository at this point in the history
  • Loading branch information
diemogebhardt committed Jan 23, 2025
1 parent 08da17b commit eb7a92d
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 68 deletions.
7 changes: 1 addition & 6 deletions compiler-core/src/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ pub fn generate_html<IO: FileSystemReader>(
),
});

// lunr.min.js, search-data.js, search_data.json and index.js
// lunr.min.js, search_data.json and index.js

files.push(OutputFile {
path: Utf8PathBuf::from("js/lunr.min.js"),
Expand All @@ -376,11 +376,6 @@ pub fn generate_html<IO: FileSystemReader>(
})
.expect("search index serialization");

files.push(OutputFile {
path: Utf8PathBuf::from("search-data.js"),
content: Content::Text(format!("window.Gleam.initSearch({});", search_data_json)),
});

files.push(OutputFile {
path: Utf8PathBuf::from("search_data.json"),
content: Content::Text(search_data_json.to_string()),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: compiler-core/src/docs/tests.rs
expression: "compile_with_markdown_pages(config, modules, pages,\nCompileWithMarkdownPagesOpts::default())"
snapshot_kind: text
---
//// LICENSE.html

Expand Down Expand Up @@ -313,11 +314,14 @@ expression: "compile_with_markdown_pages(config, modules, pages,\nCompileWithMar
});
hljs.highlightAll();
</script>
<script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script>
<script src="./js/index.js?v=0"></script>
<!-- Load the search index using JSONP to avoid CORS issues -->
<script src="./search-data.js?v=0"></script>
<script>
fetch("./search_data.json?v=0")
.then(response => response.json())
.then(data => window.Gleam.initSearch(data));
</script>
</body>
</html>
Expand Down Expand Up @@ -678,11 +682,14 @@ expression: "compile_with_markdown_pages(config, modules, pages,\nCompileWithMar
});
hljs.highlightAll();
</script>
<script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script>
<script src="./js/index.js?v=0"></script>
<!-- Load the search index using JSONP to avoid CORS issues -->
<script src="./search-data.js?v=0"></script>
<script>
fetch("./search_data.json?v=0")
.then(response => response.json())
.then(data => window.Gleam.initSearch(data));
</script>
</body>
</html>
Expand Down Expand Up @@ -1043,10 +1050,13 @@ expression: "compile_with_markdown_pages(config, modules, pages,\nCompileWithMar
});
hljs.highlightAll();
</script>
<script src="../../js/lunr.min.js?v=GLEAM_VERSION_HERE"></script>
<script src="../../js/index.js?v=0"></script>
<!-- Load the search index using JSONP to avoid CORS issues -->
<script src="../../search-data.js?v=0"></script>
<script>
fetch("../../search_data.json?v=0")
.then(response => response.json())
.then(data => window.Gleam.initSearch(data));
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: compiler-core/src/docs/tests.rs
expression: "compile(config, modules)"
snapshot_kind: text
---
//// app.html

Expand Down Expand Up @@ -349,10 +350,13 @@ expression: "compile(config, modules)"
});
hljs.highlightAll();
</script>
<script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script>
<script src="./js/index.js?v=0"></script>
<!-- Load the search index using JSONP to avoid CORS issues -->
<script src="./search-data.js?v=0"></script>
<script>
fetch("./search_data.json?v=0")
.then(response => response.json())
.then(data => window.Gleam.initSearch(data));
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: compiler-core/src/docs/tests.rs
expression: "compile(config, modules)"
snapshot_kind: text
---
//// app.html

Expand Down Expand Up @@ -424,10 +425,13 @@ expression: "compile(config, modules)"
});
hljs.highlightAll();
</script>
<script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script>
<script src="./js/index.js?v=0"></script>
<!-- Load the search index using JSONP to avoid CORS issues -->
<script src="./search-data.js?v=0"></script>
<script>
fetch("./search_data.json?v=0")
.then(response => response.json())
.then(data => window.Gleam.initSearch(data));
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: compiler-core/src/docs/tests.rs
expression: "compile(config, modules)"
snapshot_kind: text
---
//// app.html

Expand Down Expand Up @@ -350,10 +351,13 @@ expression: "compile(config, modules)"
});
hljs.highlightAll();
</script>
<script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script>
<script src="./js/index.js?v=0"></script>
<!-- Load the search index using JSONP to avoid CORS issues -->
<script src="./search-data.js?v=0"></script>
<script>
fetch("./search_data.json?v=0")
.then(response => response.json())
.then(data => window.Gleam.initSearch(data));
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: compiler-core/src/docs/tests.rs
expression: "compile(config, modules)"
snapshot_kind: text
---
//// app.html

Expand Down Expand Up @@ -319,10 +320,13 @@ expression: "compile(config, modules)"
});
hljs.highlightAll();
</script>
<script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script>
<script src="./js/index.js?v=0"></script>
<!-- Load the search index using JSONP to avoid CORS issues -->
<script src="./search-data.js?v=0"></script>
<script>
fetch("./search_data.json?v=0")
.then(response => response.json())
.then(data => window.Gleam.initSearch(data));
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: compiler-core/src/docs/tests.rs
expression: "compile(config, modules)"
snapshot_kind: text
---
//// app.html

Expand Down Expand Up @@ -423,10 +424,13 @@ function for a fallback value.</p>
});
hljs.highlightAll();
</script>
<script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script>
<script src="./js/index.js?v=0"></script>
<!-- Load the search index using JSONP to avoid CORS issues -->
<script src="./search-data.js?v=0"></script>
<script>
fetch("./search_data.json?v=0")
.then(response => response.json())
.then(data => window.Gleam.initSearch(data));
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: compiler-core/src/docs/tests.rs
expression: "compile(config, modules)"
snapshot_kind: text
---
//// app.html

Expand Down Expand Up @@ -353,10 +354,13 @@ expression: "compile(config, modules)"
});
hljs.highlightAll();
</script>
<script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script>
<script src="./js/index.js?v=0"></script>
<!-- Load the search index using JSONP to avoid CORS issues -->
<script src="./search-data.js?v=0"></script>
<script>
fetch("./search_data.json?v=0")
.then(response => response.json())
.then(data => window.Gleam.initSearch(data));
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: compiler-core/src/docs/tests.rs
expression: "compile(config, modules)"
snapshot_kind: text
---
//// app.html

Expand Down Expand Up @@ -323,10 +324,13 @@ expression: "compile(config, modules)"
});
hljs.highlightAll();
</script>
<script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script>
<script src="./js/index.js?v=0"></script>
<!-- Load the search index using JSONP to avoid CORS issues -->
<script src="./search-data.js?v=0"></script>
<script>
fetch("./search_data.json?v=0")
.then(response => response.json())
.then(data => window.Gleam.initSearch(data));
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: compiler-core/src/docs/tests.rs
expression: "compile_with_markdown_pages(config, vec![], pages,\nCompileWithMarkdownPagesOpts::default())"
snapshot_kind: text
---
//// one.html

Expand Down Expand Up @@ -313,10 +314,13 @@ expression: "compile_with_markdown_pages(config, vec![], pages,\nCompileWithMark
});
hljs.highlightAll();
</script>
<script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script>
<script src="./js/index.js?v=0"></script>
<!-- Load the search index using JSONP to avoid CORS issues -->
<script src="./search-data.js?v=0"></script>
<script>
fetch("./search_data.json?v=0")
.then(response => response.json())
.then(data => window.Gleam.initSearch(data));
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: compiler-core/src/docs/tests.rs
expression: "compile_with_markdown_pages(config, modules, pages,\nCompileWithMarkdownPagesOpts { hex_publish: Some(DocContext::Build) })"
snapshot_kind: text
---
//// LICENSE.html

Expand Down Expand Up @@ -306,11 +307,14 @@ expression: "compile_with_markdown_pages(config, modules, pages,\nCompileWithMar
});
hljs.highlightAll();
</script>
<script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script>
<script src="./js/index.js?v=0"></script>
<!-- Load the search index using JSONP to avoid CORS issues -->
<script src="./search-data.js?v=0"></script>
<script>
fetch("./search_data.json?v=0")
.then(response => response.json())
.then(data => window.Gleam.initSearch(data));
</script>
</body>
</html>
Expand Down Expand Up @@ -664,11 +668,14 @@ expression: "compile_with_markdown_pages(config, modules, pages,\nCompileWithMar
});
hljs.highlightAll();
</script>
<script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script>
<script src="./js/index.js?v=0"></script>
<!-- Load the search index using JSONP to avoid CORS issues -->
<script src="./search-data.js?v=0"></script>
<script>
fetch("./search_data.json?v=0")
.then(response => response.json())
.then(data => window.Gleam.initSearch(data));
</script>
</body>
</html>
Expand Down Expand Up @@ -1022,10 +1029,13 @@ expression: "compile_with_markdown_pages(config, modules, pages,\nCompileWithMar
});
hljs.highlightAll();
</script>
<script src="../../js/lunr.min.js?v=GLEAM_VERSION_HERE"></script>
<script src="../../js/index.js?v=0"></script>
<!-- Load the search index using JSONP to avoid CORS issues -->
<script src="../../search-data.js?v=0"></script>
<script>
fetch("../../search_data.json?v=0")
.then(response => response.json())
.then(data => window.Gleam.initSearch(data));
</script>
</body>
</html>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: compiler-core/src/docs/tests.rs
expression: "compile(config, modules)"
snapshot_kind: text
---
//// app.html

Expand Down Expand Up @@ -353,10 +354,13 @@ expression: "compile(config, modules)"
});
hljs.highlightAll();
</script>
<script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script>
<script src="./js/index.js?v=0"></script>
<!-- Load the search index using JSONP to avoid CORS issues -->
<script src="./search-data.js?v=0"></script>
<script>
fetch("./search_data.json?v=0")
.then(response => response.json())
.then(data => window.Gleam.initSearch(data));
</script>
</body>
</html>
8 changes: 0 additions & 8 deletions compiler-core/src/docs/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,11 +551,3 @@ fn output_of_search_data_json() {
let json = serde_to_string(&data).unwrap();
insta::assert_snapshot!(json);
}

#[test]
fn output_of_search_data_js() {
let data = create_sample_search_data();
let json = serde_to_string(&data).unwrap();
let json_wrapped_in_js = format!("window.Gleam.initSearch({});", json);
insta::assert_snapshot!(json_wrapped_in_js);
}
Loading

0 comments on commit eb7a92d

Please sign in to comment.