快乐的梦鱼 1 kuukausi sitten
vanhempi
commit
192df287c1
3 muutettua tiedostoa jossa 188 lisäystä ja 2 poistoa
  1. 6 2
      App.vue
  2. 46 0
      pages/exportToAiIch.vue
  3. 136 0
      scripts/ExportToAi/ich.ts

+ 6 - 2
App.vue

@@ -8,11 +8,11 @@
     }"
   >
     <NuxtLoadingIndicator />
-    <NavBar />
+    <NavBar v-if="showNavAndFooter" />
     <main>
       <NuxtPage />
     </main>
-    <Footer />
+    <Footer v-if="showNavAndFooter" />
   </a-config-provider>
 </template>
 
@@ -27,6 +27,10 @@ import VueAMap, {initAMapApiLoader} from '@vuemap/vue-amap';
 import { registryConvert } from './common/ConvertRgeistry'
 import { registerAllFormComponents } from './components/dynamicf';
 
+const showNavAndFooter = computed(() => {
+  return route.path !== '/exportToAiIch';
+});
+
 if (import.meta.client) {
   initAMapApiLoader({
     key: '212b86dc49a5116a34e945d31da7ad14',

+ 46 - 0
pages/exportToAiIch.vue

@@ -0,0 +1,46 @@
+<template>
+  <div>
+    <button @click="downloadMarkdown" class="download-btn">下载Markdown</button>
+    <div class="markdown-content" v-if="markdownText">
+      <pre>{{ markdownText }}</pre>
+    </div>
+  </div>
+</template>
+
+<script setup lang="ts">
+import { ref, onMounted } from 'vue';
+
+</script>
+
+<style scoped>
+.download-btn {
+  margin: 20px;
+  padding: 10px 20px;
+  background-color: #1890ff;
+  color: white;
+  border: none;
+  border-radius: 4px;
+  cursor: pointer;
+  font-size: 16px;
+}
+
+.download-btn:hover {
+  background-color: #40a9ff;
+}
+
+.markdown-content {
+  margin: 20px;
+  padding: 20px;
+  background-color: #f5f5f5;
+  border-radius: 4px;
+  overflow: auto;
+}
+
+pre {
+  white-space: pre-wrap;
+  word-wrap: break-word;
+  font-family: 'Courier New', Courier, monospace;
+  font-size: 14px;
+  line-height: 1.6;
+}
+</style>

+ 136 - 0
scripts/ExportToAi/ich.ts

@@ -0,0 +1,136 @@
+
+import { writeFile } from 'fs/promises';
+import { GetContentListParams, type GetContentDetailItem, type GetContentListItem } from '~/api/CommonContent';
+import ProjectsContent from '~/api/inheritor/ProjectsContent';
+
+const data = [] as Array<GetContentListItem & { detail?: GetContentDetailItem }>;
+
+const markdownText = ref('');
+
+// HTML转Markdown的简单实现
+function htmlToMarkdown(html: string): string {
+  if (!html) return '';
+  
+  // 处理标题
+  html = html.replace(/<h1[^>]*>(.*?)<\/h1>/gi, '# $1\n\n');
+  html = html.replace(/<h2[^>]*>(.*?)<\/h2>/gi, '## $1\n\n');
+  html = html.replace(/<h3[^>]*>(.*?)<\/h3>/gi, '### $1\n\n');
+  
+  // 处理段落
+  html = html.replace(/<p[^>]*>(.*?)<\/p>/gi, '$1\n\n');
+  
+  // 处理加粗
+  html = html.replace(/<strong[^>]*>(.*?)<\/strong>/gi, '**$1**');
+  html = html.replace(/<b[^>]*>(.*?)<\/b>/gi, '**$1**');
+  
+  // 处理斜体
+  html = html.replace(/<em[^>]*>(.*?)<\/em>/gi, '*$1*');
+  html = html.replace(/<i[^>]*>(.*?)<\/i>/gi, '*$1*');
+  
+  // 处理列表
+  html = html.replace(/<ul[^>]*>([\s\S]*?)<\/ul>/gi, (match, content) => {
+    return content.replace(/<li[^>]*>(.*?)<\/li>/gi, '- $1\n') + '\n';
+  });
+  
+  html = html.replace(/<ol[^>]*>([\s\S]*?)<\/ol>/gi, (match, content, index) => {
+    let count = 1;
+    return content.replace(/<li[^>]*>(.*?)<\/li>/gi, () => {
+      return `${count++}. $1\n`;
+    }) + '\n';
+  });
+  
+  // 处理图片
+  html = html.replace(/<img[^>]*src="([^"]*)"[^>]*alt="([^"]*)"[^>]*>/gi, '![$2]($1)');
+  
+  // 处理链接
+  html = html.replace(/<a[^>]*href="([^"]*)"[^>]*>(.*?)<\/a>/gi, '[$2]($1)');
+  
+  // 处理换行
+  html = html.replace(/<br[^>]*>/gi, '\n');
+  
+  // 去除所有HTML标签
+  html = html.replace(/<[^>]*>/g, '');
+  
+  // 处理多余的换行
+  html = html.replace(/\n\s*\n/g, '\n\n');
+  
+  return html.trim();
+}
+// 生成Markdown文本
+function generateMarkdown(): string {
+  let md = '';
+  
+  data.forEach((item, index) => {
+    if (index > 0) {
+      md += '\n\n---\n\n';
+    }
+    
+    // 基本信息
+    md += `# ${item.title}\n\n`;
+    md += `${item.desc || '无描述'}\n\n`;
+    md += `## 基本信息\n\n`;
+    md += `- 非遗级别: ${item.levelText || '无'}\n`;
+    md += `- 非遗类别: ${item.ichTypeText || '无'}\n`;
+    md += `- 地区: ${item.district || '无'}\n`;
+    md += `- 批次: ${item.batchText || '无'}\n`;
+    md += `- 保护单位: ${item.unit || '无'}\n\n`;
+    
+    // 图片
+    if (item.images && item.images.length > 0) {
+      md += `## 图片\n\n`;
+      item.images.forEach(image => {
+        md += `![${item.title}图片](${image})\n\n`;
+      });
+    }
+    
+    // 详细信息
+    if (item.detail) {
+      // 简介
+      if (item.detail.intro) {
+        md += `## 简介\n\n`;
+        md += htmlToMarkdown(item.detail.intro) + '\n\n';
+      }
+      
+      // 传承人
+      if (item.detail.inheritorsList && item.detail.inheritorsList.length > 0) {
+        md += `## 相关传承人\n\n`;
+        if (item.detail.inheritor) {
+          md += htmlToMarkdown(item.detail.inheritor) + '\n\n';
+        }
+        
+        item.detail.inheritorsList.forEach(inheritor => {
+          md += `### ${inheritor.title}\n\n`;
+          md += `级别:${inheritor.levelLext || '无'}\n\n`;
+          if (inheritor.image) {
+            md += `![传承人头像](${inheritor.image})\n\n`;
+          }
+        });
+      }
+      
+      // 传习所
+      if (item.detail.ichSitesList && item.detail.ichSitesList.length > 0) {
+        md += `## 相关传习所\n\n`;
+        item.detail.ichSitesList.forEach(site => {
+          md += `### ${site.title}\n\n`;
+          md += `级别:${site.levelLext || '无'}\n\n`;
+          md += `地址:${site.address || '无'}\n\n`;
+          if (site.image) {
+            md += `![传习所图片](${site.image})\n\n`;
+          }
+        });
+      }
+    }
+  });
+  
+  return md;
+}
+
+(await ProjectsContent.getContentList(new GetContentListParams(), 1, 1000)).list.forEach(item => {
+  data.push(item);
+});
+for (const item of data) {
+  item.detail = (await ProjectsContent.getContentDetail(item.id)) as GetContentDetailItem;
+}
+// 生成Markdown文本
+markdownText.value = generateMarkdown();
+await writeFile('非遗项目数据.md', markdownText.value);