Skip to content

Commit

Permalink
Merge pull request #657 from kalamuna/kstat-180
Browse files Browse the repository at this point in the history
KSTAT-180: Allow passing in a single source file
  • Loading branch information
RobLoach authored May 11, 2024
2 parents f1e1c40 + 65b4045 commit 37c4109
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 2 deletions.
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>

0 comments on commit 37c4109

Please sign in to comment.