Skip to content

Commit fe603d6

Browse files
committed
fix(api): Use forked hugo-data-to-pages. Add async.
- Replaces hugo-data-to-pages with forked repo that accepts a config object and uses a more recent version of js-yaml. - Uses async to wait for scripts to complete.
1 parent dd2b07c commit fe603d6

File tree

10 files changed

+212
-262
lines changed

10 files changed

+212
-262
lines changed

api-docs/package.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

api-docs/scripts/generate-openapi-articles.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ const execCommand = (command) => {
1818
}
1919
};
2020

21-
22-
2321
// Function to generate data from OpenAPI
2422
function generateDataFromOpenAPI(specFile, dataOutPath, articleOutPath) {
2523
if (!fs.existsSync(dataOutPath)) {
@@ -36,20 +34,23 @@ function generateDataFromOpenAPI(specFile, dataOutPath, articleOutPath) {
3634
// Example usage of generateDataFromOpenAPI function
3735
// generateDataFromOpenAPI('path/to/openapi-file.yml', 'path/to/paths-output-folder', 'path/to/metadata-output-folder');
3836

39-
function generatePagesFromArticleData(articlesPath, contentPath) {
37+
const generatePagesFromArticleData = async (articlesPath, contentPath) => {
38+
let config = {
39+
root: '.', //Root hugo folder, can be empty
40+
dataFolder: articlesPath, //Data folder path (will fetch ALL files from here)
41+
type: "api", //Type name [basically layout] (save it under "layouts/NAME/single.html" or themes/THEME/layouts/NAME/single.html). Can be overridden on individual pages by defining "type" under "fields"
42+
pages: "articles", //Pages element in your data, in case it's "posts" or "articles" etc.
43+
contentPath: contentPath, //Path to content directory (in case it's not "content")
44+
hugoPath: `${DOCS_ROOT}/node_modules/.bin/hugo-extended` //Path to hugo binary (if global, e.g. /snap/bin/hugo)
45+
}
46+
configJson = `'${JSON.stringify(config)}'`;
47+
console.log('Clean...')
4048
execCommand(
41-
`HUGO_DATAPAGES_DATA_PATH=${articlesPath} \
42-
HUGO_DATAPAGES_ELEMENT=articles \
43-
HUGO_DATAPAGES_TYPE=api \
44-
HUGO_DATAPAGES_CONTENT_PATH=${contentPath} \
45-
node ${path.join(DOCS_ROOT, '/hugo-data-to-pages/hugo.js')} clean --force`
49+
`node ./node_modules/hugo-data-to-pages/hugo.js clean --force --config=${configJson}`
4650
)
51+
console.log('Generate...')
4752
execCommand(
48-
`HUGO_DATAPAGES_DATA_PATH=${articlesPath} \
49-
HUGO_DATAPAGES_ELEMENT=articles \
50-
HUGO_DATAPAGES_TYPE=api \
51-
HUGO_DATAPAGES_CONTENT_PATH=${contentPath} \
52-
node ${path.join(DOCS_ROOT, '/hugo-data-to-pages/hugo.js')} generate`
53+
`node ./node_modules/hugo-data-to-pages/hugo.js generate --config=${configJson}`
5354
)
5455
}
5556

api-docs/yarn.lock

Lines changed: 0 additions & 15 deletions
This file was deleted.

hugo-data-to-pages/.gitignore

Lines changed: 0 additions & 7 deletions
This file was deleted.

hugo-data-to-pages/LICENSE.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

hugo-data-to-pages/README.md

Lines changed: 0 additions & 46 deletions
This file was deleted.

hugo-data-to-pages/hugo.js

Lines changed: 0 additions & 125 deletions
This file was deleted.

hugo-data-to-pages/package.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
},
1717
"dependencies": {
1818
"axios": "^1.7.4",
19+
"hugo-data-to-pages": "https://github.com/jstirnaman/hugo-data-to-pages",
1920
"js-yaml": "^4.1.0"
2021
},
2122
"scripts": {

0 commit comments

Comments
 (0)