Create titles as markdown entries.
This commit is contained in:
parent
aa30ceb903
commit
c0964709e1
@ -9,15 +9,19 @@ let convertor = new Convertor("./src/data/markdown-it-example.md");
|
||||
|
||||
let mdoc: string = convertor.process();
|
||||
|
||||
// Configure the client
|
||||
const api = new GhostAdminAPI({
|
||||
url: "http://localhost:2368",
|
||||
// Admin API key goes here
|
||||
key: "62ac6f5ab1479d0001082bd4:73341f843a5be78647c6f7e47d43d6cb09ec323df6d5706915df4685b3d46ce7",
|
||||
version: "v4.0",
|
||||
});
|
||||
let creation = true;
|
||||
|
||||
api.posts
|
||||
.add(JSON.parse(mdoc))
|
||||
.then((response: any) => console.log(JSON.stringify(response)))
|
||||
.catch((error: any) => console.error(error));
|
||||
if (creation) {
|
||||
// Configure the client
|
||||
const api = new GhostAdminAPI({
|
||||
url: "http://localhost:2368",
|
||||
// Admin API key goes here
|
||||
key: "62ac6f5ab1479d0001082bd4:73341f843a5be78647c6f7e47d43d6cb09ec323df6d5706915df4685b3d46ce7",
|
||||
version: "v4.0",
|
||||
});
|
||||
|
||||
api.posts
|
||||
.add(JSON.parse(mdoc))
|
||||
.then((response: any) => console.log(JSON.stringify(response)))
|
||||
.catch((error: any) => console.error(error));
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ const renderer: any = Renderer;
|
||||
|
||||
const predefinedBlocks = ["blockquote", "table", "bullet_list", "ordered_list"];
|
||||
|
||||
const headerAsMarkdown = true;
|
||||
|
||||
export class Convertor {
|
||||
markups: Record<string, any> = {};
|
||||
markers: Record<string, any> = {};
|
||||
@ -171,9 +173,24 @@ export class Convertor {
|
||||
|
||||
private processHeader(stack: Stack[], t: Token): any {
|
||||
console.log("+++++++++++++++++++++++++++++++++++++++++++++");
|
||||
console.log(JSON.stringify(t));
|
||||
console.log(JSON.stringify(stack[0].token));
|
||||
|
||||
let marker = this.builder.createMarker(t.content, []);
|
||||
return this.builder.createMarkupSection(stack[0].tag, [marker]);
|
||||
let result: any = undefined;
|
||||
|
||||
if (!headerAsMarkdown) {
|
||||
// Build the header as a <Hx /> tag
|
||||
let marker = this.builder.createMarker(t.content, []);
|
||||
result = this.builder.createMarkupSection(stack[0].tag, [marker]);
|
||||
} else {
|
||||
// build the header as a markdown card
|
||||
let tbuf: string[] = [];
|
||||
if (t.map != null)
|
||||
for (let i = t.map[0]; i < t.map[1]; i++) tbuf.push(this.lines[i]);
|
||||
result = this.builder.createCardSection("markdown", {
|
||||
markdown: tbuf.join("\n"),
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user