Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KSTAT-180: Allow passing in a single source file #657

Merged
merged 2 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/kalastatic.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ function addTwigAttachLibrary(renderData, config) {
// Executes the other functions of Kstat
export const kstat = async (config) => {
const renderData = {};
config = config || {};
config.destination = config.destination || 'build';

// Add the base url if set by the environmetn and / otherwise.
renderData.base_url = process.env.base_url || "";
Expand Down Expand Up @@ -279,9 +281,11 @@ export const kstat = async (config) => {
}

// Process each source into its corresponding destination.
const source = config.source
const source = config.source;
let stats = await fs.stat(config.source);

const destination = config.destination;
const pages = await findTwigPages(config.source);
const pages = stats.isFile() ? [config.source] : await findTwigPages(config.source);
for (const page of pages) {
const compiledHtml = await compileTwig(source, page, renderData, config).catch(err => console.log(err.message));

Expand Down
1 change: 1 addition & 0 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"build": "kalastatic",
"pretest": "npm run build",
"test": "node ./test.js",
"posttest": "npm it --prefix=single_source_file",
"preinstall": "npm install --prefix=.."
},
"kalastatic": {
Expand Down
3 changes: 3 additions & 0 deletions test/single_source_file/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Single Source File Test

This test ensures that passing a single source file to kalastatic source works.
37 changes: 37 additions & 0 deletions test/single_source_file/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions test/single_source_file/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "kalastatic-test-single_source_file",
"version": "0.0.1",
"description": "A test case for the new version of Kalastatic on single source files.",
"private": true,
"scripts": {
"build": "kalastatic",
"test": "npm run build",
"preinstall": "npm install --prefix=../.."
},
"kalastatic": {
"source": "test.html.twig"
},
"dependencies": {
"kalastatic": "file:../.."
}
}
4 changes: 4 additions & 0 deletions test/single_source_file/test.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% set title = "Hello World!" %}

<h1>{{ title }}</h1>

Loading