9.4.0 • Published 8 months ago

@holidayextras/static-site-generator v9.4.0

Weekly downloads
16
License
MIT
Repository
github
Last release
8 months ago

Static Site Generator

This is using Metalsmith and React to create a static site given params.

git clone git@github.com:holidayextras/static-site-generator.git
cd static-site-generator
npm i
npm run build
  • src src param provided for the .md file directory
  • dataSource the source to pull the content from as a function (or object as described below)
  • dataSource.type This can currently be either hxseo or prismic
  • dataSource.url This is the endpoint url for hxseo or prismic api
  • dataSource.token This is the token to pass in if the endpoint is private
  • templateDir templateDir param provided for the template directory
  • layoutDir layoutDir param provided for the layouts directory
  • destination destination param provided for the output directory
  • assets assets param provided for the assets directory

Optional You can pass in a config param too setup an object used in pages (domain, default agents etc) webpack is optional if you want to create a common js for the site and page specific js files for isomorphic pages. (This will be a link to the webpack.config.js file)

Publishing

This repoistory is available on npm here, if you wish to release a new version simply bump the package.json version number and the build process will take care of the rest.

Redux

To add a store to the SSG build when using React as a template, you can either pass in a store to the src/*.md files or you can pass in a global store into the main SSG setup.

SSG({
  src: path.join( __dirname, '..' ),
  clean: clean,
  config: config,
  showReactIDs: true,
  dataSource: {
    type: 'api',
    token: token,
    initSetup: initSetup,
    state: '../stores/mainStore.js'
  },
  layoutDir: '_layouts',
  templateDir: '_layouts/_templates',
  destination: '_site',
  assets: 'public',
  webpack: 'webpack.config.js'
})

or

---
template: mainTemplate.jsx
baseFile: baseTemplate.jsx
permalink: false
store: '../stores/mainStore.js'
dataSource:
  host: 'api1.example.com'
  port: '80'
  type: 'api1'
  query: '/getPagesFromHere?pages=test/'
  repeater: 'data'
  pageDataField: 'attributes'
  pageNameField: 'pageName'

Building multiple endpoints

You can now build multiple API endpoints within a single app / template group, please see this example on how you can do this.

app/index.js

import config from '../config/'
import initSetup from '../config/initSetup'
const token = '0123456789'

SSG({
  src: path.join( __dirname, '..' ),
  clean: clean,
  config: config,
  showReactIDs: true,
  dataSource: {
    type: 'api',
    token: token,
    initSetup: initSetup
  },
  layoutDir: '_layouts',
  templateDir: '_layouts/_templates',
  destination: '_site',
  assets: 'public',
  webpack: 'webpack.config.js'
})

config/initSetup.js

const token = process.env.HAPI_TOKEN || '9876543210'

const initSetup = params => {
  if ( !params.dataSource.type === 'api1' ) return params
  params.dataSource.query += '&token=' + token
  return params
}

export initSetup

src/api1.md

---
template: mainTemplate.jsx
baseFile: baseTemplate.jsx
permalink: false
dataSource:
  host: 'api1.example.com'
  port: '80'
  type: 'api1'
  query: '/getPagesFromHere?pages=test/'
  repeater: 'data'
  pageDataField: 'attributes'
  pageNameField: 'pageName'

src/api2.md

---
template: mainTemplate.jsx
baseFile: baseTemplate.jsx
permalink: false
dataSource:
  host: 'api2.example.com'
  query: '/getPagesFromThere?thePages=anotherTest/'
  repeater: 'articles'
  pageNameField: 'html_url'
  postPageNameChange: 'strip'
9.4.0

8 months ago

9.2.3

1 year ago

9.2.2

1 year ago

9.3.0

1 year ago

9.1.1

3 years ago

9.1.0

3 years ago

9.2.0

3 years ago

9.0.0

4 years ago

8.0.9

5 years ago

8.0.8

6 years ago

8.0.7

7 years ago

8.0.6

7 years ago

8.0.5

7 years ago

8.0.3

7 years ago

8.0.2

7 years ago

8.0.1

7 years ago

8.0.0

7 years ago

7.0.10

7 years ago

7.0.9

7 years ago

7.0.8

7 years ago

6.2.10

7 years ago

7.0.7

8 years ago

7.0.6

8 years ago

7.0.5

8 years ago

7.0.4

8 years ago

7.0.3

8 years ago

6.2.8

8 years ago

6.2.7

8 years ago

7.0.2

8 years ago

7.0.1

8 years ago

7.0.0

8 years ago

6.2.6

8 years ago

6.2.5

8 years ago

6.2.4

8 years ago

6.2.3

8 years ago

6.2.2

8 years ago

6.2.1

8 years ago

6.2.0

8 years ago

6.1.0

8 years ago

6.0.0

9 years ago

5.0.2

9 years ago

5.0.1

9 years ago

5.0.0

9 years ago

4.0.1

9 years ago

3.1.1

9 years ago

3.0.1

9 years ago

3.0.0

9 years ago

2.0.4

9 years ago

2.0.3

9 years ago

2.0.2

9 years ago

2.0.1

10 years ago

2.0.0

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.0.0

10 years ago