Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrew Plaza
committed
Mar 6, 2017
1 parent
d562227
commit 027671f
Showing
4 changed files
with
31 additions
and
14 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
#!/bin/bash | ||
|
||
NODE_ENV=development node_modules/.bin/babel-node --presets 'react,es2015' react-dev/render_to_file.js | ||
# sed -i '1 i\---\nlayout: default\n---' src/_layouts/post.html | ||
|
||
|
||
|
||
staticHTML=( "src/_layouts/post.html" ) | ||
#staticHTML=( "src/_layouts/post.html" ) | ||
|
||
# add --- layout: default to frontmatter | ||
# React doesn't do front matter very well | ||
|
||
for i in "${staticHTML[@]}" | ||
do | ||
sed -i '1 i\---\nlayout: default\n---' $i | ||
done | ||
#for i in "${staticHTML[@]}" | ||
#do | ||
# sed -i '1 i\---\nlayout: default\n---' $i | ||
#done |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,39 @@ | ||
import React from 'react'; | ||
import { renderToStaticMarkup } from 'react-dom/server'; | ||
import { html_beautify } from 'js-beautify'; | ||
import fs from 'fs-extra'; | ||
import fse from 'fs-extra'; | ||
import _ from 'lodash'; | ||
|
||
import Post from './pages/post'; | ||
import Default from './pages/default'; | ||
|
||
const files = { | ||
post: './src/_layouts/post.html' // any files you want to add default layout to | ||
}; // add them to this object | ||
|
||
function renderStatic(template, file) { | ||
const html = html_beautify(renderToStaticMarkup(template)); | ||
fs.outputFile(file, html, (err) => { | ||
fse.outputFile(file, html, (err) => { | ||
console.log(err); | ||
}); | ||
} | ||
|
||
renderStatic(<Post />, './src/_layouts/post.html'); | ||
renderStatic(<Post />, files.post); | ||
renderStatic(<Default />, './src/_layouts/default.html'); | ||
|
||
///iterate through files object and add : | ||
//--- | ||
//layout: default | ||
//--- | ||
//to them | ||
_.forOwn(files, (key, value) => { | ||
const data = fse.readFileSync(key); | ||
console.log(key); | ||
const fd = fse.openSync(key, 'w+'); | ||
const buffer = '---\nlayout: default\n---'; | ||
fse.writeFileSync(fd, buffer); //write layout | ||
fse.appendFileSync(fd, data); | ||
//written = fse.writeSync(fd, data, 0, data.length, buffer.length); //append data previously in file | ||
fse.close(fd); | ||
}); | ||
|
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