Permalink
Please sign in to comment.
Showing
with
149 additions
and 96 deletions.
- +0 −1 clearPages.sh
- +43 −38 convert_files.js
- +97 −49 create_structure.js
- +4 −4 deploy.sh
- +4 −3 package.json
- +1 −1 wiki-master
1
clearPages.sh
@@ -1,3 +1,2 @@ | ||
#!/bin/bash | ||
rm -rf ./pages/* | ||
-cp -r templates/* pages/ |
81
convert_files.js
146
create_structure.js
@@ -1,66 +1,114 @@ | ||
-/* | ||
-Automate converting the raw "wiki" into the proper hierarchy -- node script | ||
-- Readin in the file list | ||
-- Create top-level folders based on file name (Assume flat structure) | ||
-- Copy the files into their folders as index.md | ||
--- All in "Pages" | ||
-*/ | ||
- | ||
var mkdirp = require('mkdirp'); | ||
-var fs = require('fs'); | ||
+var fs = require('fs-extra'); | ||
+ | ||
+// Initialize Language folders files to copy | ||
+var languageFolders = [ | ||
+ { | ||
+ inputFile: `./wiki-master/Home.md`, | ||
+ outputFile: `./pages/en/index.md` | ||
+ }, | ||
+ { | ||
+ inputFile: `./templates/index.md`, | ||
+ outputFile: `./pages/index.md` | ||
+ }, | ||
+ { | ||
+ inputFile: `./templates/lang/_template.jsx`, | ||
+ outputFile: `./pages/en/_template.jsx` | ||
+ }, | ||
+ { | ||
+ inputFile: `./templates/_template.jsx`, | ||
+ outputFile: `./pages/_template.jsx` | ||
+ } | ||
+]; | ||
// Get File list | ||
-fs.readdir('./wiki-master', function(err, files) { | ||
- if(err) throw err; | ||
- | ||
+fs.readdir('./wiki-master', function (err, files) { | ||
+ if (err) throw err; | ||
+ | ||
// List all of the *.lang folders for later | ||
var folderList = files.filter(file => { | ||
return /\w{2}\.lang/.test(file); | ||
}); | ||
- | ||
+ | ||
// Get English/Top Level files | ||
- var fileList = files.filter(function(file) { | ||
- return (/\.md$/.test(file) && !/^_|\w{2}\.lang|Home\.md/.test(file)); | ||
- }).map(function(file) { | ||
+ var fileList = files.filter(function (file) { | ||
+ return (/\.md$/.test(file) && !/^_|\w{2}\.lang/.test(file)); | ||
+ }).map(function (file) { | ||
// Make directories/filenames | ||
- var filename = file; | ||
- var dir = 'en/' + file.replace('.md', ''); | ||
- return { filename: filename, dir: dir}; | ||
+ if (/Home\.md/i.test(file)) { | ||
+ return { | ||
+ inputFile: file, | ||
+ outputDir: 'en/' | ||
+ }; | ||
+ } else { | ||
+ return { | ||
+ inputFile: file, | ||
+ outputDir: 'en/' + file.replace('.md', '') | ||
+ }; | ||
+ } | ||
}); | ||
- | ||
+ | ||
// Get non-english files | ||
- var extra = folderList.reduce((thisList, subFolder) => { | ||
- var langDir = subFolder.match(/^\w{2}/)[0] + '/', | ||
- langFiles = fs.readdirSync('./wiki-master/' + subFolder); | ||
- return thisList.concat(langFiles.filter(function(file) { | ||
- return (/\.md$/.test(file) && !/^_|\w{2}\.lang|Home\.md/.test(file)); | ||
- }).map(function(file) { | ||
- // Make directories/filenames | ||
- var filename = subFolder + '/' + file; | ||
- var dir = langDir + file.replace('.md', ''); | ||
- return { filename: filename, dir: dir}; | ||
- })); | ||
- },[]); | ||
- | ||
- // [ [ stuff] ] | ||
- // [ stuff ] | ||
- | ||
- console.log('extra', extra); | ||
- | ||
- fileList = fileList.concat(extra); | ||
- | ||
+ var extra = folderList.reduce((thisList, langSubFolder) => { | ||
+ var langDir = langSubFolder.match(/^\w{2}/)[0] + '/', | ||
+ langFiles = fs.readdirSync('./wiki-master/' + langSubFolder); | ||
+ | ||
+ // Setup copies for later | ||
+ languageFolders.push({ | ||
+ inputFile: `./wiki-master/` + langSubFolder + `/Home.md`, | ||
+ outputFile: `./pages/` + langDir + 'index.md' | ||
+ }); | ||
+ languageFolders.push({ | ||
+ inputFile: `./templates/lang/_template.jsx`, | ||
+ outputFile: `./pages/` + langDir + '_template.jsx' | ||
+ }); | ||
+ | ||
+ // Append foreign language files to the copy list | ||
+ return thisList.concat( | ||
+ langFiles.filter(function (file) { | ||
+ return (/\.md$/.test(file) && !/^_|\w{2}\.lang/.test(file)); | ||
+ }).map(function (file) { | ||
+ // Make directories/filenames | ||
+ if (/Home\.md/i.test(file)) { | ||
+ return { | ||
+ inputFile: file, | ||
+ outputDir: langDir | ||
+ }; | ||
+ } else { | ||
+ return { | ||
+ inputFile: langSubFolder + '/' + file, | ||
+ outputDir: langDir + file.replace('.md', '') | ||
+ }; | ||
+ } | ||
+ }) | ||
+ ); | ||
+ }, []); | ||
+ | ||
+ // Create folders and copy *.md files | ||
createFolders(fileList); | ||
+ | ||
+ // Copy language templates and templates files to each language | ||
+ try { | ||
+ languageFolders.forEach(file => { | ||
+ fs.copySync(file.inputFile, file.outputFile); | ||
+ }); | ||
+ } catch (err) { | ||
+ throw err; | ||
+ } | ||
}); | ||
+// Create a folder base | ||
function createFolders(fileList) { | ||
- fileList.forEach(function(fileobj) { | ||
- // Create directory | ||
- console.log(fileobj.dir); | ||
- mkdirp('./pages/' + fileobj.dir, function(err) { | ||
- if(err) throw err; | ||
+ fileList.forEach(function (fileobj) { | ||
+ try { | ||
+ // Create directory | ||
+ fs.mkdirsSync('./pages/' + fileobj.outputDir); | ||
+ | ||
// Copy File | ||
- var newFileName = './pages/'+fileobj.dir+"/index.md"; | ||
- fs.createReadStream('./wiki-master/' + fileobj.filename).pipe(fs.createWriteStream(newFileName)); | ||
- }); | ||
- }); | ||
+ fs.copySync('./wiki-master/' + fileobj.inputFile, | ||
+ './pages/' + fileobj.outputDir + '/index.md'); | ||
+ } catch (err) { | ||
+ throw err; | ||
+ } | ||
+ }); | ||
} |
8
deploy.sh
7
package.json
2
wiki-master
@@ -1 +1 @@ | ||
-Subproject commit 9896da063a780127437235826f10fdff241c3beb | ||
+Subproject commit e9fd4a9e0e073bd32f2fac883ae31d3382cf0a15 |
0 comments on commit
1918481