Create titles as markdown entries.

This commit is contained in:
Laur Ivan 2022-06-28 22:46:58 +02:00
parent aa30ceb903
commit c0964709e1
2 changed files with 35 additions and 14 deletions

View File

@ -9,15 +9,19 @@ let convertor = new Convertor("./src/data/markdown-it-example.md");
let mdoc: string = convertor.process(); let mdoc: string = convertor.process();
// Configure the client let creation = true;
const api = new GhostAdminAPI({
if (creation) {
// Configure the client
const api = new GhostAdminAPI({
url: "http://localhost:2368", url: "http://localhost:2368",
// Admin API key goes here // Admin API key goes here
key: "62ac6f5ab1479d0001082bd4:73341f843a5be78647c6f7e47d43d6cb09ec323df6d5706915df4685b3d46ce7", key: "62ac6f5ab1479d0001082bd4:73341f843a5be78647c6f7e47d43d6cb09ec323df6d5706915df4685b3d46ce7",
version: "v4.0", version: "v4.0",
}); });
api.posts api.posts
.add(JSON.parse(mdoc)) .add(JSON.parse(mdoc))
.then((response: any) => console.log(JSON.stringify(response))) .then((response: any) => console.log(JSON.stringify(response)))
.catch((error: any) => console.error(error)); .catch((error: any) => console.error(error));
}

View File

@ -14,6 +14,8 @@ const renderer: any = Renderer;
const predefinedBlocks = ["blockquote", "table", "bullet_list", "ordered_list"]; const predefinedBlocks = ["blockquote", "table", "bullet_list", "ordered_list"];
const headerAsMarkdown = true;
export class Convertor { export class Convertor {
markups: Record<string, any> = {}; markups: Record<string, any> = {};
markers: Record<string, any> = {}; markers: Record<string, any> = {};
@ -171,9 +173,24 @@ export class Convertor {
private processHeader(stack: Stack[], t: Token): any { private processHeader(stack: Stack[], t: Token): any {
console.log("+++++++++++++++++++++++++++++++++++++++++++++"); console.log("+++++++++++++++++++++++++++++++++++++++++++++");
console.log(JSON.stringify(t)); console.log(JSON.stringify(stack[0].token));
let result: any = undefined;
if (!headerAsMarkdown) {
// Build the header as a <Hx /> tag
let marker = this.builder.createMarker(t.content, []); let marker = this.builder.createMarker(t.content, []);
return this.builder.createMarkupSection(stack[0].tag, [marker]); 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;
} }
} }