From ff9b49db0d001b5800e3367b6e01bfa8664f04c3 Mon Sep 17 00:00:00 2001 From: Luis Llamas Date: Thu, 22 Sep 2022 13:12:53 +0200 Subject: [PATCH] Added compatibility with .html content --- sample/my-sample.html | 64 +++++++++++++++++++++++++++++++++++++++++++ src/post.ts | 20 ++++++++++---- 2 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 sample/my-sample.html diff --git a/sample/my-sample.html b/sample/my-sample.html new file mode 100644 index 0000000..6e05cdc --- /dev/null +++ b/sample/my-sample.html @@ -0,0 +1,64 @@ +--- +title: Sample documents of extention "WordPress Post" +status: publish +date: "2021-12-31T23:00:00" +categories: [vscode] +tags: [vscode, typescript] +--- + +

This is sample document of extention "WordPress Post". + Test of Line Break.

+

Test of new paragraph.

+

Test of headline level 2

+

Test of headline level 2.

+

Test of headline level 3

+

Test of headline level 3.

+

Test of codeblock

+ +
+    
+    import requests
+    SITE_URL = "https://yoursite"
+    API_URL = f"{SITE_URL}/wp-json/wp/v2/"
+    AUTH_USER = "zzzz"
+    AUTH_PASS = "xxxx xxxx xxxx xxxx xxxx IxxxxYT4"
+    
+    res = requests.get(API_URL, auth=(AUTH_USER, AUTH_PASS))
+    print(res.json())
+    
+
+ +

Test of table

+ + + + + + + + + + + + + + + + + + + + + + + + + +
labelAPI
category/wp-json/wp/v2/categories
tag/wp-json/wp/v2/tags
media/wp-json/wp/v2/media
post/wp-json/wp/v2/posts
+

Test of image

+

Abount local(relative path) image, this extention uploads and replaces local url to wordpress url:

+

front-matter

+

Abount www() image, this extension is ignore this.

+

sample image

+

Done

+

That's all.

\ No newline at end of file diff --git a/src/post.ts b/src/post.ts index bea7df2..e90f49a 100644 --- a/src/post.ts +++ b/src/post.ts @@ -29,8 +29,8 @@ export const post = async (context: Context) => { // check document file extension context.debug(`[03S] check file extension`); - if (docParsedPath.ext !== ".md") { - const msg = `Not a Markdow file: ${docParsedPath.base}`; + if (docParsedPath.ext !== ".md" && docParsedPath.ext !== ".html") { + const msg = `Not a Markdow or Html file: ${docParsedPath.base}`; context.debug(`[03Z] ${msg}`); throw new Error(msg); } @@ -69,10 +69,18 @@ export const post = async (context: Context) => { } context.debug(`[04E] detected document slug : ${postData["slug"]}`); - // markdown -> post data content - context.debug(`[06S] convert to html`); - postData["content"] = MarkdownIt().render(markdown.content); - context.debug(`[06E] converted to html`); + // document content + if(docParsedPath.ext === ".md") + { + // markdown -> post data content + context.debug(`[06S] convert to html`); + postData["content"] = MarkdownIt().render(markdown.content); + context.debug(`[06E] converted to html`); + } + if(docParsedPath.ext === ".html") + { + postData["content"] = markdown.content; + } // upload attached image file, change src context.debug(`[07S] process attached images`);