Skip to content

Commit d2e5b91

Browse files
🔧 Add config to generator
1 parent 571e687 commit d2e5b91

4 files changed

Lines changed: 9 additions & 8 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@staart/site",
3-
"version": "0.9.61",
3+
"version": "0.9.62",
44
"module": "dist/module.js",
55
"main": "dist/index.js",
66
"bin": "./dist/index.js",

src/config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import gitUrlParse from "git-url-parse";
66
import { cached } from "./cache";
77
const explorer = cosmiconfig("staart");
88

9-
export const getConfig = async () => {
9+
let customConfig: StaartSiteConfig | undefined = undefined;
10+
export const getConfig = async (userConfig?: StaartSiteConfig) => {
11+
if (userConfig) customConfig = userConfig;
1012
const config = await cached<StaartSiteConfig>("config", _getConfig);
11-
if (config) return config;
13+
if (config) return { ...config, ...customConfig } as StaartSiteConfig;
1214
throw new Error("Config not found");
1315
};
1416

src/generator.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { removeHeading } from "./parse";
1818
import { getConfig } from "./config";
1919
import { SitemapStream, streamToPromise } from "sitemap";
2020
import color from "color";
21+
import { StaartSiteConfig } from "./interfaces";
2122

2223
export const getTemplate = async () => {
2324
const result = await cached<string>("template", async () => {
@@ -111,9 +112,9 @@ export const getCss = async () => {
111112
);
112113
};
113114

114-
export const generate = async () => {
115+
export const generate = async (customConfig?: StaartSiteConfig) => {
115116
ensureDir(await getDistPath());
116-
const config = await getConfig();
117+
const config = await getConfig(customConfig);
117118
if (!config.noHome) await generatePage("index.html", await getHomeContent());
118119
if (!config.noSitemap) await generateSitemap();
119120
const files = (await listContentFiles()).filter(

src/module.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
import { generate } from "./generator";
2-
3-
export default generate;
1+
export { generate } from "./generator";

0 commit comments

Comments
 (0)