Created
March 25, 2020 17:23
-
-
Save keima/9dcccf7dcbd7663dfd69f0f1a10ee99b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path') | |
const fs = require('fs').promises | |
const glob = require('glob-promise') | |
const dayjs = require('dayjs') | |
const FILE_METADATA = 'info.json' | |
const FILE_MARKDOWN = 'README.md' | |
async function main() { | |
const metadataPaths = await glob(`./items/*/${FILE_METADATA}`) | |
for (let metadataPath of metadataPaths) { | |
const metadataRaw = await fs.readFile(metadataPath, 'utf8') | |
const metadata = JSON.parse(metadataRaw) | |
const createdAt = dayjs(metadata.created_at) | |
const updatedAt = dayjs(metadata.updated_at) | |
const mdPath = metadataPath.replace(FILE_METADATA, FILE_MARKDOWN) | |
const mdContent = await fs.readFile(mdPath, 'utf8') | |
console.log(metadata.tags) | |
const data = `--- | |
title: "${metadata.title.replace(/\"(.*)\"/, '\\"$1\\"')}" | |
date: ${metadata.created_at} | |
lastmod: ${metadata.updated_at} | |
thumbnail: images/qiita-exported.png | |
categories: ['Qiita'] | |
tags: [${metadata.tags.map(tag => `'${tag}'`).join(', ')}] | |
toc: true | |
draft: false | |
--- | |
**注意!** | |
この記事はQiitaにて公開されていた内容をimportしたものです。 | |
これらの内容は場合によっては陳腐化していて役に立たなくなっていたり、有害であったり、現在の著者の主張と異なることがあります。 | |
皆様の判断の上でご利用いただけますと幸いです(度を超してヤバいものは著者に連絡して頂ければ対応します m(\_ \_)m) | |
----- | |
${mdContent} | |
` | |
await fs.writeFile(`./hugofy/${createdAt.format('YYYY-MM-DD')}-${metadata.id}.md`, data) | |
console.log('ok: ' + metadata.title) | |
} | |
} | |
main().catch((e) => { | |
console.error(e) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment