Skip to content

Commit

Permalink
feat: blog形式のテキストのダウンロードに対応
Browse files Browse the repository at this point in the history
  • Loading branch information
mnao305 committed Jul 7, 2024
1 parent 10f2514 commit 21675e6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/content/modules/blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { fileDownload } from './download'
export const blogDL = (postContent: PostContentBlog, filepath: string): void => {
const json = JSON.parse(postContent.comment) as Blog
const blog = json.ops

let blog_text = ""

for (let i = 0; i < blog.length; i++) {
const element = blog[i]
if (typeof element.insert !== 'string' && element.insert.fantiaImage) {
Expand All @@ -15,7 +18,15 @@ export const blogDL = (postContent: PostContentBlog, filepath: string): void =>
} else if (typeof element.insert !== 'string' && element.insert.image) {
// 外部を参照している画像
fileDownload(element.insert.image, filepath, String(i) + urlToExt(element.insert.image))
} else if (typeof element.insert === 'string') {
// テキスト
// TODO: リンクなどへの対応。Markdown化するかは検討
blog_text += element.insert + "\n"
}
}
// TODO: テキストのダウンロード

// テキストのダウンロード
if (blog_text !== "") {
fileDownload(`data:text/plain;charset=UTF-8,${blog_text}`, filepath, 'text.txt')
}
}

0 comments on commit 21675e6

Please sign in to comment.