Skip to content

Commit

Permalink
fixing issue 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Plaza committed Mar 6, 2017
1 parent d562227 commit 027671f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
11 changes: 5 additions & 6 deletions generate-static.sh
@@ -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
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -56,7 +56,6 @@
"ejs": "^2.5.5",
"eslint-config-rallycoding": "^3.1.0",
"flexboxgrid": "^6.3.1",
"fs": "0.0.1-security",
"fs-extra": "^1.0.0",
"fuzzy": "^0.1.3",
"gzip": "^0.1.0",
Expand Down
28 changes: 25 additions & 3 deletions react-dev/render_to_file.js
@@ -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);
});

5 changes: 1 addition & 4 deletions src/_layouts/post.html
@@ -1,6 +1,3 @@
---
layout: default
---
<div class="single-post-content" id="single-post-content">
<div class="paper-wrapper" id="post-static-content" style="-webkit-tap-highlight-color:rgba(0,0,0,0);-moz-box-sizing:border-box;-webkit-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;box-sizing:border-box;font-family:Roboto, sans-serif;background-color:#303030;box-shadow:0 14px 45px rgba(0, 0, 0, 0.25),
0 10px 18px rgba(0, 0, 0, 0.22);border-radius:2px;mui-prepared:;transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;color:#fafafa;">
Expand All @@ -12,5 +9,5 @@ <h1 class="post-title" itemprop="name headline">{{ page.title }}</h1>
</header>
<div class="post-content" itemprop="articleBody">{{ content }}</div>
</article>
</div>
</div>
</div>

0 comments on commit 027671f

Please sign in to comment.