-
Notifications
You must be signed in to change notification settings - Fork 3
/
Gulpfile.js
87 lines (82 loc) · 2.44 KB
/
Gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import path from 'path'
import gulp from 'gulp'
import {getPageInfo, ampCreator} from './src/index.js'
import AmpOptimizer from '@ampproject/toolbox-optimizer'
const port = 4488
/**
* @type {PagesUrlsMap}
*/
const urls = {
example: {
local: {base: 'http://localhost:' + port + '/default/'},
prod: {base: 'https://cap.bemit.codes/'},
},
}
const pages = {
example: {
paths: {
styles: 'example/styles',
stylesInject: 'main.css',
style: 'main.scss',
html: 'example/html',
dist: 'example/build',
distStyles: 'styles',
},
},
}
const isDev = process.env.NODE_ENV === 'development'
const tasks = ampCreator({
port: port,
dist: 'example/build',
srcMedia: 'example/media',
distMedia: 'media',
pages: pages,
collections: [{
fm: (file) => 'example/data/' + path.basename(file).slice(0, '.twig'.length * -1) + '.md',
tpl: 'example/html/pages/*.twig',
base: '',
pageId: 'example',
}, {
fm: 'example/data/blog/*.md',
tpl: 'example/html/blog.twig',
base: 'blog',
pageId: 'example',
}],
ampOptimizer: !isDev ? AmpOptimizer.create({}) : undefined,
// minifyHtml: false,
cleanInlineCSS: !isDev,
// for css injection of non-AMP pages:
// cssInjectTag: '<style>',
twig: {
data: {ampEnabled: true},
fmMap: (data, files) => {
const pageId = files.pageId
const {
pagePath, pageBase,
} = getPageInfo(files, urls, pageId, isDev ? 'local' : 'prod')
const pageData = pages[pageId]
return {
pageId: pageId,
styleSheets: [
pageData.paths.stylesInject,
],
head: {
title: data.attributes.title,
description: data.attributes.description,
lang: data.attributes.lang,
},
links: {
canonical: pageBase + pagePath,
origin: pageBase,
cdn: isDev ? 'http://localhost:' + port + '/' : pageBase,
},
content: data.body,
}
},
logicLoader: async () => {
return {}
},
},
prettyUrlExtensions: ['html'],
})
Object.keys(tasks).forEach(taskName => gulp.task(taskName, tasks[taskName]))