Skip to content

Commit

Permalink
Release/v1.1.0 (#214)
Browse files Browse the repository at this point in the history
* ContentManager, server, env: Separated production and preview keys.

* App, server, log: Added version logging.

* BlogPage, LandingPage: Added estimated read time.

* BlogPage, LandingPage: Only external links open in a new window.

* Router: Switched next and previous posts.

* BlogPage: Added styles for secondary headers.

* BlogPage: Added H2 styling.

* BlogPage, LandingPage: Added temporary workaround for dropcap issue adobe-webplatform/dropcap.js#19

* BlogPage: Updated dropcap styling.

* readme, license, package: Updated readme and license.

* package: Version bump.
  • Loading branch information
umamialex authored Jun 20, 2016
1 parent 7fa5476 commit 9e4d448
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 47 deletions.
11 changes: 10 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
Copyright 2015 Alexander Martin
Copyright 2016 Alexander Martin Licensed under the Educational Community License
, Version 2.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.osedu.org/licenses/ECL-2.0

Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
42 changes: 34 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,46 @@ $ npm install

## Build
```bash
$ gulp build
$ SA_URL='http://suitupalex.com:80' npm run build
```

## Development
## Production Build
```bash
$ gulp dev
$ gulp dev:strict # This will run ESLint checks.
$ npm run prod
```

## Test
## Run
```bash
$ npm install -g mocha jest-cli
$ npm test
$ DEBUG='sa*' \
SA_CONTENTFUL_PREVIEW_ACCESS_TOKEN=preview_token
SA_CONTENTFUL_PRODUCTION_ACCESS_TOKEN=production_token
SA_CONTENTFUL_SPACE=space_id
SA_PORT=8080 \
SA_URL=http://localhost:8080 \
SA_FETCH_INTERVAL=30 \
npm run watch
```

## Watch
```bash
$ DEBUG='sa*' \
SA_CONTENTFUL_PREVIEW_ACCESS_TOKEN=preview_token
SA_CONTENTFUL_PRODUCTION_ACCESS_TOKEN=production_token
SA_CONTENTFUL_SPACE=space_id
SA_PORT=8080 \
SA_URL=http://localhost:8080 \
SA_FETCH_INTERVAL=30 \
npm start
```

## License
No License. Copyright 2015 Alexander Martin.
Copyright 2016 Alexander Martin Licensed under the Educational Community License
, Version 2.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.osedu.org/licenses/ECL-2.0

Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
11 changes: 7 additions & 4 deletions backend/ContentManager/ContentManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ const contentful = require('contentful')
class ContentManager {
constructor(options) {
this.log = options.log
this.isProduction = options.isProduction

this.client = contentful.createClient({
space: options.space
, accessToken: options.accessToken
, host: options.isProduction ? undefined : 'preview.contentful.com'
, accessToken: this.isProduction
? options.productionAccessToken
: options.previewAccessToken
, host: this.isProduction ? undefined : 'preview.contentful.com'
})

this.log('Production environment:', options.isProduction)
this.log('Production environment:', this.isProduction)

this.entryReducer = this.entryReducer.bind(this)

Expand Down Expand Up @@ -80,7 +83,7 @@ class ContentManager {
case 'blogPost': {
fields.date = new Date(fields.publishDate).getTime()

if (fields.date > new Date().getTime()){
if (this.isProduction && fields.date > new Date().getTime()){
return result
}

Expand Down
6 changes: 5 additions & 1 deletion backend/server.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
'use strict'

const pkg = require('../package.json')
const env = require('../lib/env')
const log = require('../lib/log')
const paths = require('../lib/paths')

const ContentManager = require('./ContentManager/ContentManager')
const HttpServer = require('./HttpServer/HttpServer')

log.server(`Application started: v${pkg.version}`)

const contentManager = new ContentManager({
accessToken: env.CONTENTFUL_ACCESS_TOKEN
productionAccessToken: env.CONTENTFUL_PRODUCTION_ACCESS_TOKEN
, previewAccessToken: env.CONTENTFUL_PREVIEW_ACCESS_TOKEN
, fetchInterval:
parseFloat(env.FETCH_INTERVAL ? env.FETCH_INTERVAL : 30) * 60000
, isProduction: env.NODE_ENV === 'production'
Expand Down
26 changes: 13 additions & 13 deletions dist/base.bundle.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion frontend/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react'

import Router from '../Router/Router.jsx'

import pkg from '../../package.json'
import {web as log} from 'log'

import './app.sass'
Expand All @@ -13,7 +14,7 @@ class App extends React.Component {

window.app = this

log('Application started.')
log(`Application started: v${pkg.version}`)

log('Connecting to socket:', props.url)
const socket = io(props.url)
Expand Down
21 changes: 14 additions & 7 deletions frontend/Page/BlogPage/BlogPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ class BlogPage extends React.Component {
}

applyDropCap() {
const dropcap = this.refs.dropcap

log('Applying dropcap.')
window.Dropcap.layout(
document.querySelectorAll('.blog-page-dropcap')
, 3
)

dropcap.dcapjsStrut = null
window.Dropcap.layout(dropcap, 3)
}

componentDidMount() {
Expand All @@ -47,6 +48,7 @@ class BlogPage extends React.Component {
const body = this.getContent('body')
const dropcap = body ? body.slice(0, 1) : ''
const restOfBody = body ? body.slice(1) : ''
const readTime = Math.ceil(_.words(body).length / 275)

const formattedDate = moment(this.getContent('publishDate'))
.format('MMMM Do, YYYY')
Expand Down Expand Up @@ -83,14 +85,19 @@ class BlogPage extends React.Component {
updateRoute={props.updateRoute}
>
<h1>&ldquo;{title}&rdquo;</h1>
<p className='blog-page-date'>{formattedDate}</p>
<p className='blog-page-date'>
{formattedDate} | {readTime} minute read
</p>
<hr/>
<span className='blog-page-dropcap'>{dropcap}</span>
<span className='blog-page-dropcap' ref='dropcap'>{dropcap}</span>
<ReactMarkdown
className='blog-page-body'
renderers={{
Link: props => (
<a href={props.href} target='_blank'>{props.children}</a>
<a
href={props.href}
target={props.href.indexOf('/') === 0 ? '' : '_blank'}
>{props.children}</a>
)
}}
source={restOfBody}
Expand Down
29 changes: 26 additions & 3 deletions frontend/Page/BlogPage/blog-page.sass
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,34 @@
max-width: 50ch
box-sizing: border-box

h1, &-date
h1, h2, &-date
text:
align: center
transform: uppercase

h2
font:
size: 1em
weight: bold
letter-spacing: 0.1em
margin: 2em
position: relative
z-index: 1
overflow: hidden
&:before, &:after
content: '\a0'
background-color: #000
height: 0.16em
position: absolute
overflow: hidden
top: calc(50% - 0.08em)
width: calc(50% - 1em)
&:before
text-align: right
margin-left: -50%
&:after
margin-left: 1em

&-date
font:
size: 0.6em
Expand All @@ -25,8 +48,8 @@

&-dropcap
color: #f00
margin-right: 0.05em
margin-top: 0.145em
margin-right: 0.075em
margin-top: 0.11em !important

&-previous, &-next
margin-top: 1em
Expand Down
22 changes: 17 additions & 5 deletions frontend/Page/LandingPage/LandingPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,19 @@ class LandingPage extends React.Component {

applyDropCap() {
log('Applying dropcap.')
window.Dropcap.layout(
document.querySelectorAll('.blog-page-dropcap')
, 3
)

const dropcaps = document.querySelectorAll('.blog-page-dropcap')
_.forEach(dropcaps, (dropcap) => {dropcap.dcapjsStrut=null})

window.Dropcap.layout(dropcaps, 3)
}

blogMapper(blog, index) {
const body = blog.body
const summary = body.slice(0, body.indexOf('\n\n'))
const dropcap = summary ? summary.slice(0, 1) : ''
const restOfBody = summary ? summary.slice(1) : ''
const readTime = Math.ceil(_.words(body).length / 275)

const formattedDate = moment(blog.publishDate).format('MMMM Do, YYYY')

Expand All @@ -58,11 +60,21 @@ class LandingPage extends React.Component {
return (
<div className='blog-post' key={index}>
<h2>&ldquo;{blog.title}&rdquo;</h2>
<p className='blog-page-date'>{formattedDate}</p>
<p className='blog-page-date'>
{formattedDate} | {readTime} minute read
</p>
<hr/>
<span className='blog-page-dropcap'>{dropcap}</span>
<ReactMarkdown
className='blog-page-body'
renderers={{
Link: props => (
<a
href={props.href}
target={props.href.indexOf('/') === 0 ? '' : '_blank'}
>{props.children}</a>
)
}}
source={restOfBody}
/>
<p>
Expand Down
4 changes: 2 additions & 2 deletions frontend/Router/Router.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ class Router extends React.Component {
? blogPosts.indexOf(current)
: false

const previous = index !== false && index > 0
const next = index !== false && index > 0
? blogPosts[index - 1]
: null

const next = index !== false && index < blogPosts.length - 1
const previous = index !== false && index < blogPosts.length - 1
? blogPosts[index + 1]
: null

Expand Down
3 changes: 2 additions & 1 deletion lib/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
const PREFIX = 'SA'

const ENV_VARS = [
['CONTENTFUL_ACCESS_TOKEN']
['CONTENTFUL_PRODUCTION_ACCESS_TOKEN']
, ['CONTENTFUL_PREVIEW_ACCESS_TOKEN']
, ['CONTENTFUL_SPACE']
, ['FETCH_INTERVAL']
, ['PORT']
Expand Down
1 change: 1 addition & 0 deletions lib/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const debug = require('debug')
const SUBSYSTEMS = [
'contentManager'
, 'httpServer'
, 'server'
, 'web'
]

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "suitupalex.com",
"version": "1.0.1",
"version": "1.1.0",
"description": "Source code for suitupalex.com.",
"scripts": {
"build": "./scripts/build",
Expand All @@ -11,6 +11,7 @@
"watch": "./scripts/watch"
},
"author": "Alexander Martin",
"license": "ECL",
"repository": {
"type": "git",
"url": "https://github.com/suitupalex/suitupalex.com"
Expand Down

0 comments on commit 9e4d448

Please sign in to comment.