Skip to content

Commit

Permalink
Merge pull request #111 from fserb/includes
Browse files Browse the repository at this point in the history
Allow setting includes directory and non-absolute copy
  • Loading branch information
oscarotero committed Jun 22, 2021
2 parents 5aa17ff + ec792b3 commit 0f67cdc
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
5 changes: 3 additions & 2 deletions cli/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export async function run(args) {
await server(site);
}

const watcher = Deno.watchFs(site.src());
const sources = [...site.source.staticFiles].map(x => site.src(x[0]));
const watcher = Deno.watchFs([site.src(), ...sources]);
const changes = new Set();
console.log("Watching for changes...");

Expand All @@ -114,7 +115,7 @@ export async function run(args) {
}

event.paths.forEach((path) =>
changes.add(join("/", relative(site.src(), path)))
changes.add(join("./", relative(site.src(), path)))
);

// Debounce
Expand Down
2 changes: 1 addition & 1 deletion engines/eta.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class Eta extends TemplateEngine {
super(site, options);

eta.configure({
views: site.src("_includes"),
views: site.src(site.options.includes),
useWith: true,
});

Expand Down
3 changes: 2 additions & 1 deletion engines/nunjucks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export default class Nunjucks extends TemplateEngine {
constructor(site, options) {
super(site, options);

const loader = new nunjucks.FileSystemLoader(site.src("_includes"));
const loader = new nunjucks.FileSystemLoader(
site.src(site.options.includes));
this.engine = new nunjucks.Environment(loader, options);

// Update cache
Expand Down
2 changes: 1 addition & 1 deletion engines/pug.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default class Pug extends TemplateEngine {

constructor(site, options = {}) {
super(site, options);
this.includes = site.src("_includes");
this.includes = site.src(site.options.includes);

// Update cache
site.addEventListener("beforeUpdate", () => this.cache.clear());
Expand Down
2 changes: 1 addition & 1 deletion plugins/postcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function (userOptions = {}) {
return (site) => {
const options = merge({
...defaults,
includes: site.src("_includes"),
includes: site.src(site.options.includes),
}, userOptions);

const plugins = [...options.plugins];
Expand Down
5 changes: 3 additions & 2 deletions site.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const defaults = {
cwd: Deno.cwd(),
src: "./",
dest: "./_site",
includes: "_includes",
dev: false,
metrics: false,
prettyUrls: true,
Expand Down Expand Up @@ -219,7 +220,7 @@ export default class Site {
* Copy static files or directories without processing
*/
copy(from, to = from) {
this.source.staticFiles.set(join("/", from), join("/", to));
this.source.staticFiles.set(join("./", from), join("/", to));
return this;
}

Expand Down Expand Up @@ -598,7 +599,7 @@ export default class Site {
);
}

const layoutPath = this.src("_includes", layout);
const layoutPath = this.src(this.options.includes, layout);
const layoutData = await this.source.load(layoutPath, result[1]);
const engine = this.#getEngine(layout, layoutData.templateEngine);

Expand Down

0 comments on commit 0f67cdc

Please sign in to comment.