Skip to content

Commit

Permalink
initial files
Browse files Browse the repository at this point in the history
  • Loading branch information
ganow committed Feb 11, 2017
1 parent 6717344 commit 2a1a31a
Show file tree
Hide file tree
Showing 93 changed files with 371 additions and 0 deletions.
18 changes: 18 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This file is not going through babel transformation.
// So, we write it in vanilla JS
// (But you could use ES2015 features supported by your Node.js version)

module.exports = {
webpack: (config, { dev }) => {
// Perform customizations to config
config = Object.assign(
config,
{
target: "node"
}
)

// Important: return the modified config
return config
}
}
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "NODE_ENV=production node server.js"
},
"dependencies": {
"autoprefixer": "^6.7.2",
"front-matter": "^2.1.2",
"katex": "^0.7.1",
"markdown-it": "^8.2.2",
"markdown-it-highlightjs": "^2.0.0",
"markdown-it-katex": "^2.0.3",
"next": "^2.0.0-beta",
"path-match": "1.2.4",
"postcss-cssnext": "^2.9.0",
"react-katex": "^1.0.1",
"styled-jsx-postcss": "^0.1.5"
}
}
47 changes: 47 additions & 0 deletions pages/article-root.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react'
import Link from 'next/link'
import fs from 'fs'
import frontMatter from 'front-matter'

import { getArticles } from '../utils/utils'

export default class extends React.Component {
static async getInitialProps () {

return getArticles('./static/articles/').then((articles) => {
const linkParams = articles.nameList.map((articleName, i) => {
const content = fs.readFileSync(articles.pathList[i], 'utf-8')
const meta = frontMatter(content)
return {
name: articleName,
title: meta.attributes.title,
date: meta.attributes.date,
}
})
return {
linkParams: linkParams
}
})
}

render () {
return (
<div>

<ul className='articles'>
{
this.props.linkParams.map((el, i) => {
return <li className='article-list'>
<Link href={'/article?name='+el.name} as={'/article/'+el.name}><a>
<p className='article-title'>{el.title}</p>
<p className='article-date'>{el.date}</p>
</a></Link>
</li>
})
}
</ul>

</div>
)
}
}
48 changes: 48 additions & 0 deletions pages/article.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import Head from 'next/head'
import Link from 'next/link'
import React from 'react'
import fs from 'fs'
import frontMatter from 'front-matter'
const md = require('markdown-it')({
html: true
})
.use(require('markdown-it-highlightjs'))
.use(require('markdown-it-katex'))

export default class extends React.Component {
static async getInitialProps ({ query: { fname } }) {
return new Promise((resolve, reject) => {
fs.readFile(fname, 'utf-8', (error, content) => {
if (error) {
reject(error);
} else {
resolve(content)
}
})
}).then((content) => {
const meta = frontMatter(content)
// const body = md.render(meta.body)

return {
title: meta.attributes.title,
bodytxt: meta.body
}
})
}

render () {

return <div>
<Head>
<title>{this.props.title}</title>
<link rel="stylesheet" type="text/css" href="/static/css/paraiso-light.css" media="screen" />
<link rel="stylesheet" type="text/css" href="/static/css/katex.min.css" media="screen" />
</Head>

<main>
<div dangerouslySetInnerHTML={{__html: md.render(this.props.bodytxt)}} />
</main>

</div>
}
}
9 changes: 9 additions & 0 deletions pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Link from 'next/link'

export default () => (
<ul>
<li><Link href='/'><a>Home</a></Link></li>
<li><Link href='/article'><a>Articles</a></Link></li>
</ul>
)

6 changes: 6 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = () => ({
plugins: {
'postcss-cssnext': {},
require('autoprefixer')
}
})
52 changes: 52 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const { createServer } = require('http')
const { parse } = require('url')
const next = require('next')
const pathMatch = require('path-match')

const fs = require('fs')

const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
const route = pathMatch()
const match = route('/article/:name')

const files = fs.readdirSync('./static/articles').reverse()
const articleList = files.map( el => './static/articles/' + el )
const articleNameList = files.map( el => el.slice(4, -3) )

app.prepare()
.then(() => {
createServer((req, res) => {
const { pathname } = parse(req.url)
const params = match(pathname)

// /article を /article-root につけかえ
if ( route('/article')(pathname) ) {
app.render(req, res, '/article-root')
return
}

// 通常のレンダリング
if (params === false) {
handle(req, res)
return
}

const articleIndex = articleNameList.indexOf(params.name)

// ファイルが見つからない場合は 404
if (articleIndex === -1) {
app.render(req, res, '/404')
return
}

// /article のレンダリング
const fname = articleList[articleIndex]
app.render(req, res, '/article', { fname })
})
.listen(3000, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
})
})
36 changes: 36 additions & 0 deletions static/articles/000-markdown-sample.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: ブログサンプル
date: 2017.02.11
---

Markdownレンダリング用サンプルファイル。

### 数式

$$
f(x) = \int_{-\infty}^\infty \hat{f} (\xi)\,e^{2 \pi i \xi x} \,d\xi
$$

### コード

```js
function $initHighlight(block, cls) {
try {
if (cls.search(/\bno\-highlight\b/) != -1)
return process(block, true, 0x0F) +
` class="${cls}"`;
} catch (e) {
/* handle exception */
}
for (var i = 0 / 2; i < classes.length; i++) {
if (checkCondition(classes[i]) === undefined)
console.log('undefined');
}
}

export $initHighlight;
```

### はてなブログカード

<iframe class="hatenablogcard" style="width:100%;height:155px;margin:15px 0;max-width:500px;" title="はてなブログカードのような美しい外部リンクをクリック一発で作成する方法" src="https://hatenablog-parts.com/embed?url=https://nelog.jp/hatenablogcard" frameborder="0" scrolling="no"></iframe>
Binary file added static/css/fonts/KaTeX_AMS-Regular.eot
Binary file not shown.
Binary file added static/css/fonts/KaTeX_AMS-Regular.ttf
Binary file not shown.
Binary file added static/css/fonts/KaTeX_AMS-Regular.woff
Binary file not shown.
Binary file added static/css/fonts/KaTeX_AMS-Regular.woff2
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Caligraphic-Bold.eot
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Caligraphic-Bold.ttf
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Caligraphic-Bold.woff
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Caligraphic-Bold.woff2
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Caligraphic-Regular.eot
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Caligraphic-Regular.ttf
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Caligraphic-Regular.woff
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Caligraphic-Regular.woff2
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Fraktur-Bold.eot
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Fraktur-Bold.ttf
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Fraktur-Bold.woff
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Fraktur-Bold.woff2
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Fraktur-Regular.eot
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Fraktur-Regular.ttf
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Fraktur-Regular.woff
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Fraktur-Regular.woff2
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Main-Bold.eot
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Main-Bold.ttf
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Main-Bold.woff
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Main-Bold.woff2
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Main-Italic.eot
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Main-Italic.ttf
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Main-Italic.woff
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Main-Italic.woff2
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Main-Regular.eot
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Main-Regular.ttf
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Main-Regular.woff
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Main-Regular.woff2
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Math-BoldItalic.eot
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Math-BoldItalic.ttf
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Math-BoldItalic.woff
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Math-BoldItalic.woff2
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Math-Italic.eot
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Math-Italic.ttf
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Math-Italic.woff
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Math-Italic.woff2
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Math-Regular.eot
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Math-Regular.ttf
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Math-Regular.woff
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Math-Regular.woff2
Binary file not shown.
Binary file added static/css/fonts/KaTeX_SansSerif-Bold.eot
Binary file not shown.
Binary file added static/css/fonts/KaTeX_SansSerif-Bold.ttf
Binary file not shown.
Binary file added static/css/fonts/KaTeX_SansSerif-Bold.woff
Binary file not shown.
Binary file added static/css/fonts/KaTeX_SansSerif-Bold.woff2
Binary file not shown.
Binary file added static/css/fonts/KaTeX_SansSerif-Italic.eot
Binary file not shown.
Binary file added static/css/fonts/KaTeX_SansSerif-Italic.ttf
Binary file not shown.
Binary file added static/css/fonts/KaTeX_SansSerif-Italic.woff
Binary file not shown.
Binary file added static/css/fonts/KaTeX_SansSerif-Italic.woff2
Binary file not shown.
Binary file added static/css/fonts/KaTeX_SansSerif-Regular.eot
Binary file not shown.
Binary file added static/css/fonts/KaTeX_SansSerif-Regular.ttf
Binary file not shown.
Binary file added static/css/fonts/KaTeX_SansSerif-Regular.woff
Binary file not shown.
Binary file added static/css/fonts/KaTeX_SansSerif-Regular.woff2
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Script-Regular.eot
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Script-Regular.ttf
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Script-Regular.woff
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Script-Regular.woff2
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Size1-Regular.eot
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Size1-Regular.ttf
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Size1-Regular.woff
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Size1-Regular.woff2
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Size2-Regular.eot
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Size2-Regular.ttf
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Size2-Regular.woff
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Size2-Regular.woff2
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Size3-Regular.eot
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Size3-Regular.ttf
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Size3-Regular.woff
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Size3-Regular.woff2
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Size4-Regular.eot
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Size4-Regular.ttf
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Size4-Regular.woff
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Size4-Regular.woff2
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Typewriter-Regular.eot
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Typewriter-Regular.ttf
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Typewriter-Regular.woff
Binary file not shown.
Binary file added static/css/fonts/KaTeX_Typewriter-Regular.woff2
Binary file not shown.
44 changes: 44 additions & 0 deletions static/css/highlight.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* Tomorrow Night Eighties Theme */
/* Original theme - https://github.com/chriskempson/tomorrow-theme */
/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
.tomorrow-comment, pre .comment, pre .title {
color: #999999;
}

.tomorrow-red, pre .variable, pre .attribute, pre .tag, pre .regexp, pre .ruby .constant, pre .xml .tag .title, pre .xml .pi, pre .xml .doctype, pre .html .doctype, pre .css .id, pre .css .class, pre .css .pseudo {
color: #f2777a;
}

.tomorrow-orange, pre .number, pre .preprocessor, pre .built_in, pre .literal, pre .params, pre .constant {
color: #f99157;
}

.tomorrow-yellow, pre .class, pre .ruby .class .title, pre .css .rules .attribute {
color: #ffcc66;
}

.tomorrow-green, pre .string, pre .value, pre .inheritance, pre .header, pre .ruby .symbol, pre .xml .cdata {
color: #99cc99;
}

.tomorrow-aqua, pre .css .hexcolor {
color: #66cccc;
}

.tomorrow-blue, pre .function, pre .python .decorator, pre .python .title, pre .ruby .function .title, pre .ruby .title .keyword, pre .perl .sub, pre .javascript .title, pre .coffeescript .title {
color: #6699cc;
}

.tomorrow-purple, pre .keyword, pre .javascript .function {
color: #cc99cc;
}

pre code {
display: block;
background: #2d2d2d;
color: #cccccc;
font-family: Menlo, Monaco, Consolas, monospace;
line-height: 1.5;
border: 1px solid #ccc;
padding: 10px;
}
1 change: 1 addition & 0 deletions static/css/katex.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions static/css/monokai.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 72 additions & 0 deletions static/css/paraiso-light.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
Paraíso (light)
Created by Jan T. Sott (http://github.com/idleberg)
Inspired by the art of Rubens LP (http://www.rubenslp.com.br)
*/

/* Paraíso Comment */
.hljs-comment,
.hljs-quote {
color: #776e71;
}

/* Paraíso Red */
.hljs-variable,
.hljs-template-variable,
.hljs-tag,
.hljs-name,
.hljs-selector-id,
.hljs-selector-class,
.hljs-regexp,
.hljs-link,
.hljs-meta {
color: #ef6155;
}

/* Paraíso Orange */
.hljs-number,
.hljs-built_in,
.hljs-builtin-name,
.hljs-literal,
.hljs-type,
.hljs-params,
.hljs-deletion {
color: #f99b15;
}

/* Paraíso Yellow */
.hljs-title,
.hljs-section,
.hljs-attribute {
color: #fec418;
}

/* Paraíso Green */
.hljs-string,
.hljs-symbol,
.hljs-bullet,
.hljs-addition {
color: #48b685;
}

/* Paraíso Purple */
.hljs-keyword,
.hljs-selector-tag {
color: #815ba4;
}

.hljs {
display: block;
overflow-x: auto;
background: #e7e9db;
color: #4f424c;
padding: 0.5em;
}

.hljs-emphasis {
font-style: italic;
}

.hljs-strong {
font-weight: bold;
}
17 changes: 17 additions & 0 deletions utils/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import yaml from 'js-yaml'

export async function getArticles (dirname) {
return new Promise((resolve, reject) => {
fs.readdir(dirname, (error, files) => {
if (error) {
reject(error);
} else {
files.reverse()
resolve({
pathList: files.map( el => dirname + el ),
nameList: files.map( el => el.slice(4, -3) )
})
}
})
})
}

0 comments on commit 2a1a31a

Please sign in to comment.