Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require('dotenv').config({ silent: true });
- const htmlStandards = require('reshape-standard');
- const cssStandards = require('spike-css-standards');
- const jsStandards = require('spike-js-standards');
- const Contentful = require('spike-contentful');
- const marked = require('marked');
- const globImporter = require('node-sass-glob-importer');
- const moment = require('moment');
- // These variables, set in dotenv, pull access tokens from an external source.
- const env = process.env.SPIKE_ENV;
- const previewToken = process.env.PREVIEW_TOKEN;
- const deliveryToken = process.env.ACCESS_TOKEN;
- const space = process.env.SPACE_ID;
- // The variables above implement dotenv and pull access tokens from an external source.
- const locals = {};
- // Add markdown to local variables so they can be used in templates
- marked.setOptions({
- gfm: true,
- tables: true
- });
- locals.md = marked;
- // Add current year to local variables
- locals.year = new Date().getFullYear();
- // Make ENV available for templating
- locals.env = env;
- // Sitename to be used in templates
- locals.sitename = 'Site Name';
- module.exports = {
- devtool: 'source-map',
- matchers: { html: '*(**/)*.html', css: '*(**/)*.scss' },
- ignore: [
- '**/index.html',
- 'src/components/**/*.scss',
- 'src/components/**/*.html',
- '**/.*',
- 'readme.md',
- 'yarn.lock'
- ],
- module: {
- rules: [
- {
- test: /\.scss/,
- use: [
- {
- loader: 'sass-loader',
- options: {
- importer: globImporter()
- }
- }
- ]
- },
- {
- test: /\.js/,
- use: [
- {
- loader: 'import-glob'
- }
- ]
- }
- ]
- },
- dumpDirs: ['src'],
- postcss: cssStandards({
- minify: env === 'production',
- warnForDuplicates: env !== 'production',
- autoprefixer: { browsers: ['last 4 versions', '> 1%', 'ie >= 9'] }
- }),
- babel: jsStandards(),
- plugins: [
- new Contentful({
- addDataTo: locals,
- spaceId: space || 'yourspace',
- accessToken: env !== 'production' ? previewToken : deliveryToken,
- preview: env !== 'production',
- // By default, this plugin will only fetch data once when you start your watcher, for development speed purposes. This means that if you change your data, you will have to restart the watcher to pick up the changes. If you are in a phase where you are making frequent data changes and would like a more aggressive updating strategy, you can set the aggressiveRefresh option to true, and your dreams will come true. However, note that this will slow down your local development, as it will fetch and link all entires every time you save a file, so it's only recommended for temporary use.
- // aggressiveRefresh: true,
- contentTypes: [
- {
- name: 'pages',
- id: 'page',
- transform: page => {
- const transformedPage = page;
- const { metaTitle } = transformedPage.fields;
- if (metaTitle && metaTitle.includes(' | Site Name')) {
- transformedPage.fields.metaTitle = metaTitle.slice(0, -12);
- }
- if (transformedPage.fields.collection) {
- const components = transformedPage.fields.collection;
- components.forEach(section => {
- if (
- section.sys.contentType.sys.id === 'hero' &&
- section.fields.video
- ) {
- const { video } = section.fields;
- const videoTerms = video.split('/');
- const embedCode = videoTerms[videoTerms.length - 1].split(
- '?'
- );
- /* eslint-disable */
- section.fields.video = embedCode[0];
- /* eslint-enable */
- }
- });
- }
- return transformedPage;
- },
- template: {
- path: 'src/layout/page.html',
- output: page => {
- if (page.fields.slug === 'home') {
- return `index.html`;
- }
- return `${page.fields.slug}.html`;
- }
- }
- },
- {
- name: 'resources',
- id: 'resource',
- transform: resource => {
- const transformedResource = resource;
- const summary = transformedResource.fields.text
- ? transformedResource.fields.text.substring(0, 150)
- : '';
- transformedResource.fields.summary = summary;
- transformedResource.fields.summary += '...';
- const { metaTitle } = transformedResource.fields;
- if (metaTitle && metaTitle.includes(' | Site Name')) {
- transformedResource.fields.metaTitle = metaTitle.slice(0, -12);
- }
- transformedResource.thankyou = `/resources/${
- resource.fields.slug
- }/thankyou`;
- return transformedResource;
- },
- template: {
- path: 'src/layout/resource.html',
- output: resource => `resources/${resource.fields.slug}/index.html`
- }
- },
- {
- name: 'resourceThankYous',
- id: 'resource',
- transform: resource => {
- const transformedResource = resource;
- const summary = transformedResource.fields.text
- ? transformedResource.fields.text.substring(0, 150)
- : '';
- transformedResource.fields.summary = summary;
- transformedResource.fields.summary += '...';
- const { title, thankyou } = transformedResource.fields;
- transformedResource.fields.metaTitle = `Thank you for downloading '${title}'`;
- transformedResource.fields.title = `Thank you for downloading<br />“${title}”`;
- transformedResource.thankyou = thankyou
- ? marked(thankyou)
- : `<p>Check your inbox for your download link.</p><p>Want to learn more about Site Name and how we can help you manage employee relations to achieve greater business results? Choose a time and date below to schedule a 15-minute call.</p>`;
- return transformedResource;
- },
- template: {
- path: 'src/layout/thankyou.html',
- output: resource =>
- `resources/${`${resource.fields.slug}/thankyou`}.html`
- }
- },
- {
- name: 'autoLandingPages',
- id: 'resource',
- transform: resource => {
- const transformedResource = resource;
- const summary = transformedResource.fields.text
- ? transformedResource.fields.text.substring(0, 150)
- : '';
- transformedResource.fields.summary = summary;
- transformedResource.fields.summary += '...';
- const { metaTitle } = transformedResource.fields;
- if (metaTitle && metaTitle.includes(' | Site Name')) {
- transformedResource.fields.metaTitle = metaTitle.slice(0, -12);
- }
- transformedResource.thankyou = `/${resource.fields.slug}/thankyou`;
- return transformedResource;
- },
- template: {
- path: 'src/layout/landing-page.html',
- output: resource => `${resource.fields.slug}/index.html`
- }
- },
- {
- name: 'autoLandingThankYous',
- id: 'resource',
- transform: resource => {
- const transformedResource = resource;
- const summary = transformedResource.fields.text
- ? transformedResource.fields.text.substring(0, 150)
- : '';
- transformedResource.fields.summary = summary;
- transformedResource.fields.summary += '...';
- const { title, thankyou } = transformedResource.fields;
- transformedResource.fields.metaTitle = `Thank you for downloading '${title}'`;
- transformedResource.fields.title = `Thank you for downloading<br />“${title}”`;
- transformedResource.thankyou = thankyou
- ? marked(thankyou)
- : `<p>Check your inbox for your download link.</p><p>Want to learn more about Site Name and how we can help you manage employee relations to achieve greater business results? Choose a time and date below to schedule a 15-minute call.</p>`;
- return transformedResource;
- },
- template: {
- path: 'src/layout/thankyou.html',
- output: resource => `${`${resource.fields.slug}/thankyou`}.html`
- }
- },
- {
- name: 'landingPages',
- id: 'landingPage',
- transform: resource => {
- const transformedResource = resource;
- const summary = transformedResource.fields.text
- ? transformedResource.fields.text.substring(0, 150)
- : '';
- transformedResource.fields.summary = summary;
- transformedResource.fields.summary += '...';
- const { metaTitle } = transformedResource.fields;
- if (metaTitle && metaTitle.includes(' | Site Name')) {
- transformedResource.fields.metaTitle = metaTitle.slice(0, -12);
- }
- transformedResource.thankyou = `/${resource.fields.slug}/thankyou`;
- return transformedResource;
- },
- template: {
- path: 'src/layout/landing-page.html',
- output: resource => `${resource.fields.slug}/index.html`
- }
- },
- {
- name: 'landingThankYous',
- id: 'landingPage',
- transform: resource => {
- const transformedResource = resource;
- const summary = transformedResource.fields.text
- ? transformedResource.fields.text.substring(0, 150)
- : '';
- transformedResource.fields.summary = summary;
- transformedResource.fields.summary += '...';
- const { title, thankyou } = transformedResource.fields;
- transformedResource.fields.metaTitle = `Thank you for downloading '${title}'`;
- transformedResource.fields.title = `Thank you for downloading<br />“${title}”`;
- transformedResource.thankyou = thankyou
- ? marked(thankyou)
- : `<p>Check your inbox for your download link.</p><p>Want to learn more about Site Name and how we can help you manage employee relations to achieve greater business results? Choose a time and date below to schedule a 15-minute call.</p>`;
- return transformedResource;
- },
- template: {
- path: 'src/layout/thankyou.html',
- output: resource => `${`${resource.fields.slug}/thankyou`}.html`
- }
- },
- {
- name: 'blogs',
- id: 'blogPost',
- filters: {
- order: '-fields.date',
- limit: 1000
- },
- transform: blog => {
- const transformedBlog = blog;
- const date = transformedBlog.fields.date
- ? moment(transformedBlog.fields.date).format('MMM Do, YYYY')
- : '';
- const summary = transformedBlog.fields.text
- ? transformedBlog.fields.text.substring(0, 150)
- : '';
- transformedBlog.fields.date = date;
- transformedBlog.fields.summary = summary;
- transformedBlog.fields.summary += '...';
- const { metaTitle } = transformedBlog.fields;
- if (metaTitle && metaTitle.includes(' | Site Name')) {
- transformedBlog.fields.metaTitle = metaTitle.slice(0, -12);
- }
- return transformedBlog;
- },
- template: {
- path: 'src/layout/blog.html',
- output: blog => `blog/${blog.fields.slug}.html`
- }
- },
- {
- name: 'news',
- id: 'news',
- filters: {
- order: '-fields.date'
- },
- transform: news => {
- const transformedNews = news;
- transformedNews.fields.date = moment(
- transformedNews.fields.date
- ).format('MMM Do, YYYY');
- return transformedNews;
- },
- template: {
- path: 'src/layout/news.html',
- output: news =>
- // BUG: this no worky
- // if (!news.fields.externalSourceUrl) {
- // return `about/news/${news.fields.slug}.html`;
- // }
- `about-us/news/${news.fields.slug}.html`
- }
- },
- {
- name: 'menus',
- id: 'menu'
- },
- {
- name: 'menuLinks',
- id: 'menuLink'
- },
- {
- name: 'ctas',
- id: 'cta'
- },
- {
- name: 'authors',
- id: 'author'
- },
- {
- name: 'customers',
- id: 'customer'
- },
- {
- name: 'testimonials',
- id: 'testimonial'
- },
- {
- name: 'teamMembers',
- id: 'teamMember',
- filters: {
- order: '-sys.updatedAt'
- }
- },
- {
- name: 'grids',
- id: 'grid'
- },
- {
- name: 'notifications',
- id: 'notification'
- },
- {
- name: 'redirects',
- id: 'redirect'
- }
- ],
- json: 'data.json'
- })
- ],
- reshape: htmlStandards({
- locals: () => locals,
- minify: env === 'production',
- retext: []
- }),
- entry: { 'assets/main': ['./src/assets/main.js'] }
- };
Add Comment
Please, Sign In to add comment