Skip to content

Commit d955cbd

Browse files
Copilotruibaby
andauthored
Add configuration option to control article publishing after import (#5)
* Initial plan * Initial plan for adding publish option to article import Co-authored-by: ruibaby <21301288+ruibaby@users.noreply.github.com> * Add publish option to article import functionality Co-authored-by: ruibaby <21301288+ruibaby@users.noreply.github.com> * Remove package-lock.json Signed-off-by: Ryan Wang <i@ryanc.cc> --------- Signed-off-by: Ryan Wang <i@ryanc.cc> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ruibaby <21301288+ruibaby@users.noreply.github.com> Co-authored-by: Ryan Wang <i@ryanc.cc>
1 parent 01b54d7 commit d955cbd

4 files changed

Lines changed: 44 additions & 20 deletions

File tree

ui/src/components/PostExportDropdownItem.vue

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,7 @@ async function onSubmit(data: ExportForm) {
3535
const { ContentExporter } = await import('@/class/contentExporter');
3636
try {
3737
exporting.value = true;
38-
await ContentExporter.export(
39-
post.post,
40-
data.type,
41-
data.includeImages,
42-
data.imageExportMode
43-
);
38+
await ContentExporter.export(post.post, data.type, data.includeImages, data.imageExportMode);
4439
modal.value?.close();
4540
Toast.success('导出成功');
4641
} catch (error) {
@@ -54,19 +49,19 @@ async function onSubmit(data: ExportForm) {
5449
<template>
5550
<VDropdownItem @click="display = true">导出</VDropdownItem>
5651
<VModal
52+
v-if="display"
53+
ref="modal"
5754
:centered="false"
5855
title="导出"
5956
mount-to-body
60-
ref="modal"
61-
v-if="display"
6257
@close="display = false"
6358
>
6459
<FormKit
60+
id="post-export-form"
61+
v-slot="{ value }"
6562
type="form"
6663
name="post-export-form"
67-
id="post-export-form"
6864
@submit="onSubmit"
69-
#default="{ value }"
7065
>
7166
<FormKit label="导出格式" type="select" name="type" :options="exportTypeOptions" />
7267
<FormKit v-if="value.type !== 'pdf'" label="包含图片" type="checkbox" name="includeImages" />
@@ -86,7 +81,7 @@ async function onSubmit(data: ExportForm) {
8681
<template #footer>
8782
<VSpace>
8883
<!-- @vue-ignore -->
89-
<VButton type="secondary" @click="$formkit.submit('post-export-form')" :loading="exporting">
84+
<VButton type="secondary" :loading="exporting" @click="$formkit.submit('post-export-form')">
9085
导出
9186
</VButton>
9287
<VButton @click="modal?.close()">取消</VButton>

ui/src/utils/image.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export function isImageFile(file: File): boolean {
1717
);
1818
}
1919

20-
2120
/**
2221
* Extract image references from markdown content
2322
*
@@ -52,7 +51,11 @@ export function extractHTMLImageReferences(htmlContent: string): string[] {
5251

5352
while ((match = imageRegex.exec(htmlContent)) !== null) {
5453
const imagePath = match[1];
55-
if (!imagePath.startsWith('http://') && !imagePath.startsWith('https://') && !imagePath.startsWith('data:')) {
54+
if (
55+
!imagePath.startsWith('http://') &&
56+
!imagePath.startsWith('https://') &&
57+
!imagePath.startsWith('data:')
58+
) {
5659
images.push(imagePath);
5760
}
5861
}
@@ -101,7 +104,7 @@ export function getImageFileExtension(imageUrl: string): string {
101104
const pathname = url.pathname;
102105
const extension = pathname.split('.').pop()?.toLowerCase();
103106

104-
if (extension && SUPPORTED_IMAGE_EXTENSIONS.some(ext => ext.slice(1) === extension)) {
107+
if (extension && SUPPORTED_IMAGE_EXTENSIONS.some((ext) => ext.slice(1) === extension)) {
105108
return extension;
106109
}
107110

ui/src/views/tabs/MarkdownImport.vue

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const fileInput = ref<HTMLInputElement | null>(null);
3232
const folderInput = ref<HTMLInputElement | null>(null);
3333
const imageInput = ref<HTMLInputElement | null>(null);
3434
const convertToHtml = ref(false);
35+
const publishAfterImport = ref(true);
3536
3637
interface ImportItem {
3738
id: string;
@@ -322,9 +323,11 @@ async function createPost(item: ImportItem, raw: string) {
322323
postRequest: postToCreate,
323324
});
324325
325-
await consoleApiClient.content.post.publishPost({
326-
name: data.metadata.name,
327-
});
326+
if (publishAfterImport.value) {
327+
await consoleApiClient.content.post.publishPost({
328+
name: data.metadata.name,
329+
});
330+
}
328331
}
329332
330333
function handleClear() {
@@ -409,6 +412,16 @@ const showAlert = useSessionStorage('plugin:content-tools:markdown-import-alert'
409412
></FormKit>
410413
</div>
411414

415+
<div class=":uno: mt-3">
416+
<FormKit
417+
v-model="publishAfterImport"
418+
type="checkbox"
419+
label="导入后发布文章"
420+
:disabled="isBusy"
421+
help="取消选择时,导入的文章将保存为草稿"
422+
></FormKit>
423+
</div>
424+
412425
<div v-if="importQueue.length > 0" class=":uno: mt-5 space-y-4">
413426
<div class=":uno: flex items-center justify-between">
414427
<div class=":uno: h-7 flex items-center gap-3 text-sm text-gray-600">

ui/src/views/tabs/WordImport.vue

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import MingcuteTimeLine from '~icons/mingcute/time-line';
2828
const fileInput = ref<HTMLInputElement | null>(null);
2929
const folderInput = ref<HTMLInputElement | null>(null);
3030
const convertToMarkdown = ref(false);
31+
const publishAfterImport = ref(true);
3132
3233
interface ImportItem {
3334
id: string;
@@ -279,9 +280,11 @@ async function createPost(item: ImportItem, html: string) {
279280
postRequest: postToCreate,
280281
});
281282
282-
await consoleApiClient.content.post.publishPost({
283-
name: data.metadata.name,
284-
});
283+
if (publishAfterImport.value) {
284+
await consoleApiClient.content.post.publishPost({
285+
name: data.metadata.name,
286+
});
287+
}
285288
}
286289
287290
function handleClear() {
@@ -344,6 +347,16 @@ const showAlert = useSessionStorage('plugin:content-tools:word-import-alert', tr
344347
></FormKit>
345348
</div>
346349

350+
<div class=":uno: mt-3">
351+
<FormKit
352+
v-model="publishAfterImport"
353+
type="checkbox"
354+
label="导入后发布文章"
355+
:disabled="isBusy"
356+
help="取消选择时,导入的文章将保存为草稿"
357+
></FormKit>
358+
</div>
359+
347360
<div v-if="importQueue.length > 0" class=":uno: mt-5 space-y-4">
348361
<div class=":uno: flex items-center justify-between">
349362
<div class=":uno: h-7 flex items-center gap-3 text-sm text-gray-600">

0 commit comments

Comments
 (0)