Skip to content

Commit

Permalink
Update converter to read asciid doc file to interpret canonical url
Browse files Browse the repository at this point in the history
  • Loading branch information
javamind committed Dec 31, 2023
1 parent 2278733 commit d080eb2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions extension/model.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ export interface IndexBlogData extends IndexData {
imgteaser: string;
modeDev: boolean;
blog: boolean;
subdirectory: string;
}
1 change: 1 addition & 0 deletions extension/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ export interface IndexBlogData extends IndexData {
modeDev: boolean;
// boolean to say if the page is a blog post or not
blog: boolean;
subdirectory : string;
}
7 changes: 6 additions & 1 deletion extension/read-asciidoctor.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,23 @@ function extReadAsciidoc(options) {
file.attributes = file.ast.getAttributes();
var filename = file.path.substring(file.path.lastIndexOf("/") + 1, file.path.lastIndexOf("."));
var dir = '';
var subdirectory = '';
if (options.dirNames && options.dirNames.length > 0) {
options.dirNames.forEach(function (dirname) {
if (file.path.lastIndexOf(dirname) > 0) {
dir = file.path.substring(file.path.lastIndexOf(dirname) + dirname.length, file.path.lastIndexOf("/"));
subdirectory = dirname;
}
});
}
else {
if (file.path.lastIndexOf("blog/") > 0) {
dir = file.path.substring(file.path.lastIndexOf("blog/") + "blog/".length, file.path.lastIndexOf("/"));
subdirectory = 'blog';
}
if (file.path.lastIndexOf("training/") > 0) {
dir = file.path.substring(file.path.lastIndexOf("training/") + "training/".length, file.path.lastIndexOf("/"));
subdirectory = 'training';
}
}
var indexData = {
Expand All @@ -63,6 +67,7 @@ function extReadAsciidoc(options) {
category: file.attributes.category,
teaser: file.attributes.teaser,
imgteaser: file.attributes.imgteaser,
subdirectory: subdirectory,
modeDev: options.modeDev,
blog: true,
dir: dir,
Expand All @@ -85,7 +90,7 @@ function extReadAsciidoc(options) {
imgteaser: function () { return indexData.imgteaser; },
status: function () { return file.attributes.status; },
modedev: function () { return indexData.modeDev; },
canonicalUrl: function () { return "blog/" + dir + "/" + filename + ".html"; }
canonicalUrl: function () { return subdirectory + "/" + dir + "/" + filename + ".html"; }
};
if (file.attributes.status !== 'draft') {
file.indexData = indexData;
Expand Down
7 changes: 6 additions & 1 deletion extension/read-asciidoctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,23 @@ export function extReadAsciidoc(options: Options): Transform {
const filename = file.path.substring(file.path.lastIndexOf("/") + 1, file.path.lastIndexOf("."));

let dir = '';
let subdirectory = '';
if(options.dirNames && options.dirNames.length > 0) {
options.dirNames.forEach(dirname => {
if (file.path.lastIndexOf(dirname) > 0) {
dir = file.path.substring(file.path.lastIndexOf(dirname) + dirname.length, file.path.lastIndexOf("/"));
subdirectory = dirname;
}
})
}
else {
if (file.path.lastIndexOf("blog/") > 0) {
dir = file.path.substring(file.path.lastIndexOf("blog/") + "blog/".length, file.path.lastIndexOf("/"));
subdirectory = 'blog';
}
if (file.path.lastIndexOf("training/") > 0) {
dir = file.path.substring(file.path.lastIndexOf("training/") + "training/".length, file.path.lastIndexOf("/"));
subdirectory = 'training';
}
}

Expand All @@ -74,6 +78,7 @@ export function extReadAsciidoc(options: Options): Transform {
category: file.attributes.category,
teaser: file.attributes.teaser,
imgteaser: file.attributes.imgteaser,
subdirectory: subdirectory,
modeDev: options.modeDev,
blog: true,
dir: dir,
Expand All @@ -97,7 +102,7 @@ export function extReadAsciidoc(options: Options): Transform {
imgteaser: () => indexData.imgteaser,
status: () => file.attributes.status,
modedev: () => indexData.modeDev,
canonicalUrl: () => `blog/${dir}/${filename}.html`
canonicalUrl: () => `${subdirectory}/${dir}/${filename}.html`
};

if (file.attributes.status !== 'draft') {
Expand Down

0 comments on commit d080eb2

Please sign in to comment.