-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrewrite_md.js
53 lines (44 loc) · 1.44 KB
/
rewrite_md.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const fs = require('fs');
// Read the Markdown file
const mdText = fs.readFileSync('readme.md', 'utf-8');
const lineArray = mdText.split("\n")
const numberOfLines = lineArray.length
var i
var topic = ""
for ( i = 0; i < numberOfLines; i++){
//console.log('Line '+i+' '+lineArray[i])
if ( lineArray[i].startsWith("##") ){
topic = lineArray[i].replace(/\ /g,"_")
topic = topic.replace(/\//g,"_")
topic = topic.replace(/\(/g,"")
topic = topic.replace(/\)/g,"")
topic = topic.replace(/\,/g,"")
topic = topic.replace(/#{1,4}_/g,"").toLowerCase()
console.log('Topic: '+topic)
}
if ( topic != "" && lineArray[i] != "" && lineArray[i].startsWith("##") != true){
var item = lineArray[i].replace('](',' - ')
item = item.replace(') ([',' - ')
item = item.replace('](',' - ')
item = item.replace('- [','')
item = item.replace('))','')
var content = item.split("\ -\ ")
var fileContent = `---
layout: post
repolink: "${content[1]}"
title: "${content[0]}"
description: "${content[4]}"
author: "${content[2]}"
author-link: "${content[3]}"
content-type: "${topic}"
repo: "github"
repo_title: "${content[0]}"
---`
console.log('Content: ')
console.log(fileContent)
if (!fs.existsSync('_'+topic)){
fs.mkdirSync('_'+topic);
}
fs.writeFileSync(`./_${topic}/${content[0]}_${content[2]}.md`, fileContent)
}
}