mirror of
https://github.com/litruv/lit.ruv.wtf.git
synced 2026-07-24 02:36:02 +10:00
chore: update code structure for improved readability and maintainability
This commit is contained in:
BIN
tools/blogeditor/blog-editor-0.1.12.vsix
Normal file
BIN
tools/blogeditor/blog-editor-0.1.12.vsix
Normal file
Binary file not shown.
@@ -424,6 +424,18 @@
|
|||||||
/** uploadId -> resolve(relativePath) */
|
/** uploadId -> resolve(relativePath) */
|
||||||
const _uploadResolvers = new Map();
|
const _uploadResolvers = new Map();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits markdown image target into src and optional title segment.
|
||||||
|
* @param {string} target
|
||||||
|
* @returns {{ src: string, suffix: string }}
|
||||||
|
*/
|
||||||
|
function splitImageTarget(target) {
|
||||||
|
const trimmed = target.trim();
|
||||||
|
const m = trimmed.match(/^(\S+)(\s+["'][\s\S]*["'])?$/);
|
||||||
|
if (!m) return { src: trimmed, suffix: '' };
|
||||||
|
return { src: m[1], suffix: m[2] ?? '' };
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uploads a blob URL to the extension to save to media/.
|
* Uploads a blob URL to the extension to save to media/.
|
||||||
* Returns a Promise that resolves once mediaSaved is received.
|
* Returns a Promise that resolves once mediaSaved is received.
|
||||||
@@ -552,9 +564,10 @@
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function cleanImagePaths(markdown) {
|
function cleanImagePaths(markdown) {
|
||||||
return markdown.replace(/(\!\[[^\]]*\]\()([^)]+)(\))/g, (_m, open, src, close) => {
|
return markdown.replace(/(\!\[[^\]]*\]\()([^)]+)(\))/g, (_m, open, target, close) => {
|
||||||
const rel = blobToRelative.get(src) ?? webviewToRelative.get(src);
|
const { src, suffix } = splitImageTarget(target);
|
||||||
return rel ? `${open}${rel}${close}` : `${open}${src}${close}`;
|
const rel = blobToRelative.get(src) ?? webviewToRelative.get(src);
|
||||||
|
return rel ? `${open}${rel}${suffix}${close}` : `${open}${src}${suffix}${close}`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -343,6 +343,21 @@ function buildHtml(webview) {
|
|||||||
.replace('{{THEME_CSS}}', themeCss.toString());
|
.replace('{{THEME_CSS}}', themeCss.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits markdown image target into URL/path and optional trailing title segment.
|
||||||
|
* Examples:
|
||||||
|
* data/blog/media/a.png "Caption" -> { src: data/blog/media/a.png, suffix: "Caption" }
|
||||||
|
* https://x/y.png -> { src: https://x/y.png, suffix: '' }
|
||||||
|
* @param {string} target
|
||||||
|
* @returns {{ src: string, suffix: string }}
|
||||||
|
*/
|
||||||
|
function splitImageTarget(target) {
|
||||||
|
const trimmed = target.trim();
|
||||||
|
const m = trimmed.match(/^(\S+)(\s+["'][\s\S]*["'])?$/);
|
||||||
|
if (!m) return { src: trimmed, suffix: '' };
|
||||||
|
return { src: m[1], suffix: m[2] ?? '' };
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces relative image paths in markdown with webview-safe URIs.
|
* Replaces relative image paths in markdown with webview-safe URIs.
|
||||||
* @param {string} content
|
* @param {string} content
|
||||||
@@ -350,9 +365,10 @@ function buildHtml(webview) {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function injectWebviewImageUris(content, websiteBaseUri) {
|
function injectWebviewImageUris(content, websiteBaseUri) {
|
||||||
return content.replace(/(\!\[[^\]]*\]\()([^)]+)(\))/g, (match, open, src, close) => {
|
return content.replace(/(\!\[[^\]]*\]\()([^)]+)(\))/g, (match, open, target, close) => {
|
||||||
|
const { src, suffix } = splitImageTarget(target);
|
||||||
if (/^https?:|^data:|^blob:/.test(src)) return match;
|
if (/^https?:|^data:|^blob:/.test(src)) return match;
|
||||||
return `${open}${websiteBaseUri}/${src.replace(/^\//, '')}${close}`;
|
return `${open}${websiteBaseUri}/${src.replace(/^\//, '')}${suffix}${close}`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,7 +382,10 @@ function revertWebviewImageUris(content, websiteBaseUri) {
|
|||||||
const escaped = websiteBaseUri.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
const escaped = websiteBaseUri.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||||
return content.replace(
|
return content.replace(
|
||||||
new RegExp(`(\\!\\[[^\\]]*\\]\\()${escaped}/([^)]+)(\\))`, 'g'),
|
new RegExp(`(\\!\\[[^\\]]*\\]\\()${escaped}/([^)]+)(\\))`, 'g'),
|
||||||
(_m, open, rel, close) => `${open}${rel}${close}`
|
(_m, open, target, close) => {
|
||||||
|
const { src, suffix } = splitImageTarget(target);
|
||||||
|
return `${open}${src}${suffix}${close}`;
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -399,7 +418,7 @@ function handleMessage(msg, blogDir, websiteDir) {
|
|||||||
const imgPattern = /!\[[^\]]*\]\(([^)]+)\)/g;
|
const imgPattern = /!\[[^\]]*\]\(([^)]+)\)/g;
|
||||||
let imgMatch;
|
let imgMatch;
|
||||||
while ((imgMatch = imgPattern.exec(raw)) !== null) {
|
while ((imgMatch = imgPattern.exec(raw)) !== null) {
|
||||||
const src = imgMatch[1];
|
const { src } = splitImageTarget(imgMatch[1]);
|
||||||
if (/^https?:|^data:|^blob:/.test(src)) continue;
|
if (/^https?:|^data:|^blob:/.test(src)) continue;
|
||||||
const absPath = path.join(websiteDir, src.replace(/^\//, ''));
|
const absPath = path.join(websiteDir, src.replace(/^\//, ''));
|
||||||
if (fs.existsSync(absPath)) {
|
if (fs.existsSync(absPath)) {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "blog-editor",
|
"name": "blog-editor",
|
||||||
"displayName": "Blog Editor",
|
"displayName": "Blog Editor",
|
||||||
"description": "WYSIWYG Milkdown blog post editor for this workspace",
|
"description": "WYSIWYG Milkdown blog post editor for this workspace",
|
||||||
"version": "0.1.11",
|
"version": "0.1.12",
|
||||||
"publisher": "local",
|
"publisher": "local",
|
||||||
"engines": { "vscode": "^1.80.0" },
|
"engines": { "vscode": "^1.80.0" },
|
||||||
"categories": ["Other"],
|
"categories": ["Other"],
|
||||||
|
|||||||
@@ -104,9 +104,7 @@ const obj = {
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||

|

|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## Mixed Content
|
## Mixed Content
|
||||||
|
|
||||||
|
|||||||
BIN
website/data/blog/media/paste-1778405550240-ddf8h.png
Normal file
BIN
website/data/blog/media/paste-1778405550240-ddf8h.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 984 KiB |
Reference in New Issue
Block a user