Skip to content

Commit

Permalink
Respect the forced language when passing custom records via the Node API
Browse files Browse the repository at this point in the history
  • Loading branch information
bglw committed Feb 1, 2024
1 parent fd70ca9 commit c71f9fa
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions pagefind/features/node_api/node_base.feature
Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,37 @@ Feature: Node API Base Tests
When I run "cd public && npm i && PAGEFIND_BINARY_PATH={{humane_cwd}}/$TEST_BINARY node index.js"
Then I should see "pagefind.js" in stdout
Then I should see "After close: Invalid index, does not yet exist in the Pagefind service" in stdout

# https://github.com/CloudCannon/pagefind/issues/551
@platform-unix
Scenario: Force language takes precedence over records
Given I have a "public/index.js" file with the content:
"""
import * as pagefind from "pagefind";
import fs from "fs";
import path from "path";
const run = async () => {
const { index } = await pagefind.createIndex({
forceLanguage: "fr"
});
await index.addCustomRecord({
url: "/one/",
content: "Testing file #1",
language: "pt"
});
await index.addHTMLFile({sourcePath: "two/index.html", content: "<html lang='en'><body><h1>Testing file #2</h1></body></html>"});
await index.writeFiles();
console.log("✨!");
}
run();
"""
When I run "cd public && npm i && PAGEFIND_BINARY_PATH={{humane_cwd}}/$TEST_BINARY node index.js"
Then I should see "✨!" in stdout
Then I should see the file "public/pagefind/pagefind.js"
Then I should see the file "public/pagefind/wasm.unknown.pagefind"
Then I should see the file "public/pagefind/wasm.fr.pagefind"
Then I should not see the file "public/pagefind/wasm.pt.pagefind"
Then I should not see the file "public/pagefind/wasm.en.pagefind"
2 changes: 1 addition & 1 deletion pagefind/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ pub async fn run_service() {
force_inclusion: true,
has_html_element: true,
has_old_bundle_reference: false,
language,
language: index.options.force_language.clone().unwrap_or(language),
};
let file = Fossicker::new_with_data(url, data);
let data = index.fossick_one(file).await;
Expand Down

0 comments on commit c71f9fa

Please sign in to comment.