Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions sample/my-sample.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: Sample documents of extention "WordPress Post"
status: publish
date: "2021-12-31T23:00:00"
categories: [vscode]
tags: [vscode, typescript]
---

<p>This is sample document of extention "WordPress Post".
Test of Line Break.</p>
<p>Test of new paragraph.</p>
<h2>Test of headline level 2</h2>
<p>Test of headline level 2.</p>
<h3>Test of headline level 3</h3>
<p>Test of headline level 3.</p>
<h2>Test of codeblock</h2>

<pre>
<code class="language-python">
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())
</code>
</pre>

<h2>Test of table</h2>
<table>
<thead>
<tr>
<th>label</th>
<th>API</th>
</tr>
</thead>
<tbody>
<tr>
<td>category</td>
<td>/wp-json/wp/v2/categories</td>
</tr>
<tr>
<td>tag</td>
<td>/wp-json/wp/v2/tags</td>
</tr>
<tr>
<td>media</td>
<td>/wp-json/wp/v2/media</td>
</tr>
<tr>
<td>post</td>
<td>/wp-json/wp/v2/posts</td>
</tr>
</tbody>
</table>
<h2>Test of image</h2>
<p>Abount local(relative path) image, this extention uploads and replaces local url to wordpress url:</p>
<p><img src="img/2021-12-31-231548.png" alt="front-matter"></p>
<p>Abount www() image, this extension is ignore this.</p>
<p><img src="https://picsum.photos/id/2/760/400" alt="sample image"></p>
<h2>Done</h2>
<p>That's all.</p>
20 changes: 14 additions & 6 deletions src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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`);
Expand Down