mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-06 02:30:47 -08:00
fix: import html will delete existed folder, and no Chinese error message
fixes #488
This commit is contained in:
parent
3aa18be2c5
commit
9c4aa82c8f
6 changed files with 118 additions and 87 deletions
53
src/services/wiki/wikiWorker/htmlWiki.ts
Normal file
53
src/services/wiki/wikiWorker/htmlWiki.ts
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import { isHtmlWiki } from '@/constants/fileNames';
|
||||
import { TiddlyWiki } from '@tiddlygit/tiddlywiki';
|
||||
import { remove } from 'fs-extra';
|
||||
|
||||
export async function extractWikiHTML(htmlWikiPath: string, saveWikiFolderPath: string, constants: { TIDDLYWIKI_PACKAGE_FOLDER: string }): Promise<void> {
|
||||
// tiddlywiki --load ./mywiki.html --savewikifolder ./mywikifolder
|
||||
// --savewikifolder <wikifolderpath> [<filter>]
|
||||
// . /mywikifolder is the path where the tiddlder and plugins folders are stored
|
||||
const { TIDDLYWIKI_PACKAGE_FOLDER } = constants;
|
||||
try {
|
||||
const wikiInstance = TiddlyWiki();
|
||||
wikiInstance.boot.argv = ['--load', htmlWikiPath, '--savewikifolder', saveWikiFolderPath, 'explodePlugins=no'];
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
try {
|
||||
wikiInstance.boot.startup({
|
||||
// passing bootPath inside TidGi app. fix The "path" argument must be of type string. Received undefined
|
||||
bootPath: TIDDLYWIKI_PACKAGE_FOLDER,
|
||||
callback: () => {
|
||||
resolve();
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
// removes the folder function that failed to convert.
|
||||
await remove(saveWikiFolderPath);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function packetHTMLFromWikiFolder(folderWikiPath: string, pathOfNewHTML: string, constants: { TIDDLYWIKI_PACKAGE_FOLDER: string }): Promise<void> {
|
||||
// tiddlywiki ./mywikifolder --rendertiddler '$:/core/save/all' mywiki.html text/plain
|
||||
// . /mywikifolder is the path to the wiki folder, which generally contains the tiddlder and plugins directories
|
||||
const { TIDDLYWIKI_PACKAGE_FOLDER } = constants;
|
||||
const wikiInstance = TiddlyWiki();
|
||||
// a .html file path should be provided, but if provided a folder path, we can add /index.html to fix it.
|
||||
wikiInstance.boot.argv = [folderWikiPath, '--rendertiddler', '$:/core/save/all', isHtmlWiki(pathOfNewHTML) ? pathOfNewHTML : `${pathOfNewHTML}/index.html`, 'text/plain'];
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
try {
|
||||
wikiInstance.boot.startup({
|
||||
// passing bootPath inside TidGi app. fix The "path" argument must be of type string. Received undefined
|
||||
bootPath: TIDDLYWIKI_PACKAGE_FOLDER,
|
||||
callback: () => {
|
||||
resolve();
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue