Skip to content

Commit

Permalink
add subdirectory support
Browse files Browse the repository at this point in the history
  • Loading branch information
Hadron67 committed Jul 5, 2019
1 parent 692349b commit d6f2021
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function createMainContext(){
main.invalidateID = invalidateID;
main.applyConfig = applyConfig;
main.initPages = initPages;
main.path = p => pathd.join(pathd.join('/', main.config.webRoot || '/'), p);

// Internal variables
main.logger = logger;
Expand Down
16 changes: 9 additions & 7 deletions lib/modules/category_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ function indexToPageName(i){

module.exports = params => async (app) => {
let postArg = {
tags: params.tags.path,
archive: params.archive.path,
category: params.categories.path,
tags: app.path(params.tags.path),
archive: app.path(params.archive.path),
category: app.path(params.categories.path),
};

let ext = app.ext;
Expand All @@ -24,18 +24,20 @@ module.exports = params => async (app) => {
ext.archive = postArg.archive;
ext.category = postArg.category;

params.mainPage.path = app.path(params.mainPage.path);

let mainPage = app.helper.createPaginator(compareDate, arg => app.layouts.page(arg), indexToPageName, params.mainPage.pagesPerPage, params.mainPage.path, {arg: postArg});
let archive = app.helper.createPaginator(compareDate, a => app.layouts.archive(a), indexToPageName, params.archive.pagesPerPage, params.archive.path, {arg: postArg});
let archive = app.helper.createPaginator(compareDate, a => app.layouts.archive(a), indexToPageName, params.archive.pagesPerPage, postArg.archive, {arg: postArg});
let tags = app.helper.createTags(
params.tags.path,
postArg.tags,
a => app.layouts.tag(a),
indexToPageName,
compareDate,
params.tags.pagesPerPage,
{arg: postArg}
);
let category = app.helper.createCategorizer(
params.categories.path,
postArg.category,
a => app.layouts.category(a),
indexToPageName,
compareDate,
Expand Down Expand Up @@ -66,7 +68,7 @@ module.exports = params => async (app) => {
};

app.on('init-pages', () => {
tags.registerTemplate(path.join(params.tags.path, 'index.html'), a => app.layouts.tagCloud(a), {arg: postArg});
tags.registerTemplate(path.join(postArg.tags, 'index.html'), a => app.layouts.tagCloud(a), {arg: postArg});
category.init();
});
}
2 changes: 1 addition & 1 deletion lib/modules/cname.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module.exports = () => app => {
app.on('init-pages', () => {
app.pageRegistry.register({
path: '/CNAME',
path: app.path('/CNAME'),
isStatic: false,
handle(os, cb){
os.end(app.config.domain.replace(/^https?:\/\//, ''));
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/index_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ class Handler {
module.exports = path => app => {
// let e = new TextExtractor();
// app.markdown.on('post-compile', (article, node) => article.text = e.render(node));
app.on('init-pages', () => app.pageRegistry.register(new Handler(app, path)));
app.on('init-pages', () => app.pageRegistry.register(new Handler(app, app.path(path))));
}
1 change: 1 addition & 0 deletions lib/modules/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ async function readPostFiles(dirs){

module.exports = (posts, pathBase) => async (app) => {
posts = await readPostFiles(posts);
pathBase = app.path(pathBase);
app.on('init-pages', () => {
posts = posts.map(p => app.markdown.register(app.markdown.dateToPath(pathBase), p));

Expand Down
1 change: 1 addition & 0 deletions lib/modules/rss.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class Handler {
}

module.exports = params => app => {
params.path = app.path(params.path);
params.limit === void 0 && (params.limit = -1);
app.ext.rssPath = params.path;
app.on('init-pages', () => {
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/staticDir.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ function find(dir){

module.exports = (dir, outDir) => async (app) => {
let files = await find(dir);
outDir = app.path(outDir);

app.on('init-pages', () => {
for (let file of files){
let fn = file.toString();
app.file.register(path.join('/', outDir, fn), path.join(dir, fn));
app.file.register(path.join(outDir, fn), path.join(dir, fn));
}
});
// await Promise.all(config.staticDirs.map(dir => registerStaticDir(app, config.webRoot, dir)));
Expand Down
4 changes: 2 additions & 2 deletions lib/util/complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function completeURL(main, path){
return path;
}
else {
return main.config.domain + pathd.join('/', path);
return path.charAt(0) === '/' ? path : main.path(path);
}
}

Expand All @@ -15,7 +15,7 @@ function completeImageURL(main, path){
return path;
}
else {
return pathd.join('/', main.config.imagePath, path);
return main.path(pathd.join(main.config.imagePath, path));
}
}

Expand Down

0 comments on commit d6f2021

Please sign in to comment.