Total Pageviews

Sunday 17 July 2016

基于nodejs的静态博客程序-gatsby

首先登陆vps,安装node环境。 

npm install -g typography-plugin-code
npm install -g gatsby
gatsby new gatsby-testing-site
(此命令会在当前目录下,生成gatsby-testing-site目录.
此命令相当于
gatsby new gatsby-testing-site https://github.com/gatsbyjs/gatsby-starter-default)
cd gatsby-testing-site

root@AR:~/gatsby-testing-site# ls
config.toml  css  html.js  LICENSE  loaders  node_modules  package.json  pages    README.md  utils  wrappers
root@AR:~/gatsby-testing-site# gatsby build (这个就是生成静态网站的命令)
Generating CSS
Generating Static HTML
Compiling production bundle.js
Copying assets
Done
root@AR:~/gatsby-testing-site# ls
config.toml  html.js  loaders        package.json  public     utils
css         LICENSE  node_modules  pages      README.md  wrappers
(生成了public目录)

root@AR:~/gatsby-testing-site# cd public
root@AR:~/gatsby-testing-site/public# ls
404           coffee-react  index.html  markdown  sass           toml
bundle.js      css-modules   json     postcss   styles.css       yaml
bundle.js.map  html    o     less     react       styles.css.map
(里面有index.html,可见
~/gatsby-testing-site/public/就是静态网站的根目录.你可绑定你的域名到此目录)
root@AR:~/gatsby-testing-site/public#

演示:surmount.biz.st:2356/

用这个gatsby站点源码https://github.com/gatsbyjs/gatsby-starter-default建成的站点太简陋了。
下面搞另外一个gatsby站点源码:
gatsby new gatsby-testing-blog https://github.com/gatsbyjs/gatsby-starter-blog
cd gatsby-testing-blog

root@AR:~/gatsby-testing-blog# ls
components   css      node_modules  pages      utils
config.toml  html.js  package.json  README.md  wrappers
root@AR:~/gatsby-testing-blog# gatsby build
Generating CSS
Generating Static HTML
Compiling production bundle.js
Copying assets
Done
root@AR:~/gatsby-testing-blog# ls
components   css      node_modules  pages   README.md  wrappers
config.toml  html.js  package.json  public  utils
root@AR:~/gatsby-testing-blog# cd public
root@AR:~/gatsby-testing-blog/public# ls
404.html       favicon.ico  index.html               styles.css
bundle.js      hello-world  kyle-round-small-pantheon.jpg
bundle.js.map  hi-folks     my-second-post
(~/gatsby-testing-blog/public/里面有index.html ,可见~/gatsby-testing-blog/public/就是静态网站的根目录)
root@AR:~/gatsby-testing-blog/public# nohup Rwebserver 2357 > /dev/null &
[2] 16580
root@AR:~/gatsby-testing-blog/public# nohup: 忽略输入重定向错误到标准输出端
root@AR:~/gatsby-testing-blog/public#
访问http://surmount.biz.st:2357/即可看到网站效果。

新建帖子:
root@AR:~/gatsby-testing-blog/public# cd ..
root@AR:~/gatsby-testing-blog# ls
components   css      node_modules  pages   README.md  wrappers
config.toml  html.js  package.json  public  utils
root@AR:~/gatsby-testing-blog# cd pages
root@AR:~/gatsby-testing-blog/pages# ls
2015-05-01-hello-world       404.md    kyle-round-small-pantheon.jpg
2015-05-06-my-second-post  favicon.ico    robots.txt
2015-05-28-hi-folks       index.js    _template.js
root@AR:~/gatsby-testing-blog/pages# cd 2015-05-01-hello-world
root@AR:~/gatsby-testing-blog/pages/2015-05-01-hello-world# ls
index.md  salty_egg.jpg
root@AR:~/gatsby-testing-blog/pages/2015-05-01-hello-world# cat index.md
root@AR:~/gatsby-testing-blog/pages/2015-05-01-hello-world# cd ..
root@AR:~/gatsby-testing-blog/pages# mkdir 2016-07-17-test-1
root@AR:~/gatsby-testing-blog/pages# cd 2016-07-17-test-1
root@AR:~/gatsby-testing-blog/pages/2016-07-17-test-1# nano index.md
(index.md的内容如下:
---
title: 测试1
date: "2016-07-17T22:27:32.169Z"
layout: post
---

这是测试1.

root@AR:~/gatsby-testing-blog/pages/2016-07-17-test-1# cd ../../
root@AR:~/gatsby-testing-blog# gatsby build
root@AR:~/gatsby-testing-blog# cd public
root@AR:~/gatsby-testing-blog/public# ls
2016-07-17-test-1  bundle.js.map  hi-folks             my-second-post
404.html       favicon.ico      index.html             styles.css
bundle.js       hello-world      kyle-round-small-pantheon.jpg
root@AR:~/gatsby-testing-blog/public# cd ../pages
root@AR:~/gatsby-testing-blog/pages# mkdir 2016-07-17-test-2
root@AR:~/gatsby-testing-blog/pages# cd 2016-07-17-test-2
root@AR:~/gatsby-testing-blog/pages/2016-07-17-test-2# nano index.md
(index.md的内容如下:
---
title: 测试2
date: "2016-07-17T23:07:32.169Z"
layout: post
---

这是测试2.

root@AR:~/gatsby-testing-blog/pages/2016-07-17-test-2# cd ../..
root@AR:~/gatsby-testing-blog# gatsby build

演示站点:http://surmount.biz.st:2357/,http://gb.smt.biz.st
(站点不能换页)
项目地址:https://github.com/gatsbyjs/gatsby
https://github.com/gatsbyjs/gatsby-starter-blog
https://github.com/kyleamathews/blog

https://github.com/konsumer/gatsby-starter-drunkenblog
(http://blog.jetboystudio.com)
https://github.com/iamdustan/iamdustan.github.io

https://github.com/pixelstew/gatsby-paginate ,这个项目终于让 gatsby blog能分页了。
https://github.com/lqqyt2423/gatsby-starter-blog ,这个项目也能让 gatsby blog分页,演示博客:
https://lqqyt2423.github.io/


---------------------------

https://blog.scottnonnenberg.com

A gatsby-based blog.
More on how to use this project: https://blog.scottnonnenberg.com/this-blog-is-now-open-source/
continous integration code coverage license

Forking gatsby!

Note that this project relies on my fork of gatsby. To prevent confusion, I've removed it from the dependency list, though npm scripts do refer to it. To make those scripts work, I've used npm link in my local gatsby fork directory, and npm link gatsby in this project.

Key settings

config.toml contains key data you'll want to change first. The location of the blog, author name and details, and so on.
piwik.js is excluded from the repository, but is used by html.js (to generate piwik tracking tags) and scripts/update_rankings.js (to get popularity numbers for posts). These four keys are required:
module.exports = {
  domain: 'where your piwik server is',
  siteId: 'the site number',
  site: 'the site domain',
  token: 'your API access token, used by `update-rankings` npm script',
}

Develop

npm run develop
This runs gatsby's hot-reloading development server on http://localhost:8000. It will have to be restarted if you rename, add, or remove files because webpack's watch mode doesn't handle those kinds of filesystem changes.

Build

Generate files to public/ folder. Will fail if there are outstanding git changes. Pre-gzips all files. Calls a shell script behind the scenes, so you might run into some problems on Windows.
npm run build-production # or npm run build-staging
npm run build-production -- --force # build even with outstanding git changes

Test

Run eslint and the unit tests with npm test. All utility code and React components will be tested in Node.js. npm run unit will just run the tests, and unit-watch and unit-coverage are also available for active development. Once you've generated code coverage numbers, npm run open-coverage makes it easy to open istanbul's HTML report.
You can use npm run serve to serve static files from public/ at http://localhost:8000 for manual and automated tests. A manual test script is available at tests/manual.txt - it covers the parts of the user experience without automated tests.
Once you have the static server running you can check for broken links:
npm run check-local-links
npm run check-external-links
npm run check-deep-links
npm run check-links http://localhost:8000/
Note: Due to the meta tags on each page, you'll get broken links until you've published all pages to production.

Helper scripts

npm run make-post -- "The name of your post"
Creates a new markdown file from the template at scripts/util/_postTemplate.md. Sets the new post's previous URL to the last most-recent post's URL, and updates the previous post's markdown file with the newly-generated posts URL. That was annoying to do by hand. :0)
npm run clean-post
npm run clean-post -- 5
By default processes the most recent file. If a number is provided, it will process that many most-recent posts. Removes smart quotes, duplicate links (same text as URL), and all mentions of the blog's domain (taken from config.toml) to ensure that links are all of the relative form.
npm run generate-tags
Loads all posts from pages/posts and extracts all of their tags. Ensures that a file pages/tags/TAG.js exists for every tag found. Prints out a count for each.
npm run update-rankings
Goes to my stats system (which uses Piwik), grabs the top URLs, massages the data a little bit, then updates the rank property of the frontmatter in each markdown file. If you use this, you'll want to periodically change the end date for the query.
npm run generate-rss
Generates rss.xml and atom.xml into public/. Runs as part of every build.
npm run generate-json
Generates all.json and recent.json into public/. Also runs as part of every build. I generate this file for easier syndication into other sites, like https://scottnonnenberg.com.

from  https://github.com/scottnonnenberg/blog
---------------

搭建基于gatsby的静态博客程序jazlal.li

cd /usr/local
git clone https://github.com/jazlalli/jazlal.li jazlal.li-site
cd jazlal.li-site

root@AR:/usr/local/jazlal.li-site# ls
CNAME     config.toml  html.jsx      package.json  utils
components  css node_modules  pages     README.md wrappers

root@AR:/usr/local/jazlal.li-site# npm install -g node-gyp
root@AR:/usr/local/jazlal.li-site# npm install
(npm install换成下面2个命令也可:
npm install --save gatsby
npm install --save babel-preset-react)
root@AR:/usr/local/jazlal.li-site# gatsby build
root@AR:/usr/local/jazlal.li-site# ls
CNAME     config.toml  html.jsx      package.json  public utils
components  css node_modules  pages     README.md wrappers
(生成了public目录)

root@AR:/usr/local/jazlal.li-site# cd public
root@AR:/usr/local/jazlal.li-site/public# ls
1f9e388626c69aa1cd37c5c950a53360.svg  email.svg
about       favicon.png
b6f6735c58082fd814334e28e2798e9a.svg  github.svg
blog       index.html
bundle.js       styles.css
bundle.js.map       styles.css.map
deacb42e5461d6b72813b80affab1d12.svg  twitter.svg
root@AR:/usr/local/jazlal.li-site/public#
(可见/usr/local/jazlal.li-site/public/就是静态网站的根目录)

新建源贴:
root@AR:/usr/local/jazlal.li-site/public# cd ..
root@AR:/usr/local/jazlal.li-site# ls
CNAME     config.toml  html.jsx      package.json  public utils
components  css node_modules  pages     README.md wrappers
root@AR:/usr/local/jazlal.li-site# cd pages
root@AR:/usr/local/jazlal.li-site/pages# ls
about.jsx  email.svg github.svg  robots.txt   twitter.svg
blog   favicon.png index.jsx   _template.jsx
root@AR:/usr/local/jazlal.li-site/pages# cd blog
root@AR:/usr/local/jazlal.li-site/pages/blog# ls
2016-02-18-new-beginnings drafts
2016-05-05-an-update
2016-05-18-working-with-humans
2016-06-01-thoughts-on-tech-interviews
root@AR:/usr/local/jazlal.li-site/pages/blog# mkdir 2016-09-03-1913-test-1
root@AR:/usr/local/jazlal.li-site/pages/blog# cd 2016-09-03-1913-test-1
root@AR:/usr/local/jazlal.li-site/pages/blog/2016-09-03-1913-test-1# nano index.md
root@AR:/usr/local/jazlal.li-site/pages/blog/2016-09-03-1913-test-1# cat index.md
---
title: 测试1
date: 2016-09-03
layout: post
path: "/blog/test-1/"
---

这是测试1.

root@AR:/usr/local/jazlal.li-site/pages/blog/2016-09-03-1913-test-1# cd /usr/local/jazlal.li-site
root@AR:/usr/local/jazlal.li-site# gatsby build

演示网站:http://surmount.biz.st:9830,http://jll.smt.biz.st
项目地址:https://github.com/jazlalli/jazlal.li
--------

My blog site built by Gatsby

How to Run

install dependencies:

$ yarn

develop:

$ yarn start  // aka `gatsby develop`

build:

$ yarn build  // aka `gatsby build`
$ yarn serve  // aka `gatsby serve`

when install npm, use yarn add instead of npm install.

if it have some wierd problems when running gatsby develop or gatsby build, try run gatsby clean (it will delete .cache and public folders) then do it again.


from https://github.com/baurine/gatsby-blog

-----

https://github.com/mysteriumnetwork/documentation
---------------------------------------------------------------
 
https://github.com/scastiel/gatsby-theme-potato 
---------------------------------------------------------------------

https://github.com/guanpengchn/blog, 一个基于gatsby的博客的源码
-----------------------------------------------------------------------

Gatsby + Netlify CMS Starter

Netlify Status

Note: This starter uses Gatsby v2.

This repo contains an example business website that is built with Gatsby, and Netlify CMS: Demo Link.

It follows the JAMstack architecture by using Git as a single source of truth, and Netlify for continuous deployment, and CDN distribution.

Features

  • A simple landing page with blog functionality built with Netlify CMS
  • Editable Pages: Landing, About, Product, Blog-Collection and Contact page with Netlify Form support
  • Create Blog posts from Netlify CMS
  • Tags: Separate page for posts under each tag
  • Basic directory organization
  • Uses Bulma for styling, but size is reduced by purge-css-plugin
  • Blazing fast loading times thanks to pre-rendered HTML and automatic chunk loading of JS files
  • Uses gatsby-image with Netlify-CMS preview support
  • Separate components for everything
  • Netlify deploy configuration
  • Netlify function support, see lambda folder
  • Perfect score on Lighthouse for SEO, Accessibility and Performance (wip:PWA)
  • ..and more

Prerequisites

Getting Started (Recommended)

Netlify CMS can run in any frontend web environment, but the quickest way to try it out is by running it on a pre-configured starter site with Netlify. The example here is the Kaldi coffee company template (adapted from One Click Hugo CMS). Use the button below to build and deploy your own copy of the repository:

Deploy to Netlify

After clicking that button, you’ll authenticate with GitHub and choose a repository name. Netlify will then automatically create a repository in your GitHub account with a copy of the files from the template. Next, it will build and deploy the new site on Netlify, bringing you to the site dashboard when the build is complete. Next, you’ll need to set up Netlify’s Identity service to authorize users to log in to the CMS.

Access Locally

Pulldown a local copy of the Github repository Netlify created for you, with the name you specified in the previous step

$ git clone https://github.com/[GITHUB_USERNAME]/[REPO_NAME].git
$ cd [REPO_NAME]
$ yarn
$ netlify dev # or ntl dev

This uses the new Netlify Dev CLI feature to serve any functions you have in the lambda folder.

To test the CMS locally, you'll need to run a production build of the site:

$ npm run build
$ netlify dev # or ntl dev

Media Libraries (installed, but optional)

Media Libraries have been included in this starter as a default. If you are not planning to use Uploadcare or Cloudinary in your project, you can remove them from module import and registration in src/cms/cms.js. Here is an example of the lines to comment or remove them your project.

import CMS from 'netlify-cms-app'
// import uploadcare from 'netlify-cms-media-library-uploadcare'
// import cloudinary from 'netlify-cms-media-library-cloudinary'

import AboutPagePreview from './preview-templates/AboutPagePreview'
import BlogPostPreview from './preview-templates/BlogPostPreview'
import ProductPagePreview from './preview-templates/ProductPagePreview'
import IndexPagePreview from './preview-templates/IndexPagePreview'

// CMS.registerMediaLibrary(uploadcare);
// CMS.registerMediaLibrary(cloudinary);

CMS.registerPreviewTemplate('index', IndexPagePreview)
CMS.registerPreviewTemplate('about', AboutPagePreview)
CMS.registerPreviewTemplate('products', ProductPagePreview)
CMS.registerPreviewTemplate('blog', BlogPostPreview)

Note: Don't forget to also remove them from package.json and yarn.lock / package-lock.json using yarn or npm. During the build netlify-cms-app will bundle the media libraries as well, having them removed will save you build time. Example:

yarn remove netlify-cms-media-library-uploadcare

OR

yarn remove netlify-cms-media-library-cloudinary

Getting Started (Without Netlify)

$ gatsby new [SITE_DIRECTORY_NAME] https://github.com/netlify-templates/gatsby-starter-netlify-cms/
$ cd [SITE_DIRECTORY_NAME]
$ npm run build
$ npm run serve

Setting up the CMS

Follow the Netlify CMS Quick Start Guide to set up authentication, and hosting.

Debugging

Windows users might encounter node-gyp errors when trying to npm install. To resolve, make sure that you have both Python 2.7 and the Visual C++ build environment installed.

npm config set python python2.7
npm install --global --production windows-build-tools

Full details here

MacOS users might also encounter some errors, for more info check node-gyp. We recommend using the latest stable node version.

Purgecss

This plugin uses gatsby-plugin-purgecss and bulma. The bulma builds are usually ~170K but reduced 90% by purgecss.
 
from https://github.com/reorx/gatsby-starter-netlify-cms 
-------

https://github.com/xdays/xdays.me, 分页博客的示例
------------

gatsby-paginated-blog

Gatsby starter for creating a blog with pagination

Install this starter by running from your CLI:

npx gatsby new my-paginated-blog https://github.com/NickyMeuleman/gatsby-paginated-blog

Running in development

npm run develop

from https://github.com/NickyMeuleman/gatsby-paginated-blog 

示例:https://nickymeuleman.github.io/gatsby-paginated-blog/

-----