This repository has been archived by the owner on Jun 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.html-pages.js
83 lines (76 loc) · 2.96 KB
/
webpack.html-pages.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
import HtmlWebpackPlugin from 'html-webpack-plugin'
const titleAdd = (name) => ` | ${name}`
const blogAdd = (name) => titleAdd(`Blog - ${name}`)
const getUrlPath = (url) => url.match('[^\/]+$')[0]
const prerenderParams = (url) => encodeURIComponent(JSON.stringify({string: true, params: {url}, documentUrl: getUrlPath(url)}))
const addTemplateLoaders = (indexPath, url) => {
// if (IS_PROD)
// return `!!prerender-loader?${prerenderParams(url)}!pug-loader!${indexPath}`
// else
return `!!pug-loader!${indexPath}`
}
const createHtmlPlugin = (STATIC_ENTRY_CHUNKS, BLOG_VIEW_CHUNKS) => (
chunkName, filename,
append = '', template = addTemplateLoaders('./src/index.pug', `/${chunkName}`),
extras = {}
) => new HtmlWebpackPlugin({
...extras,
NODE_ENV: process.env.NODE_ENV,
filename,
template,
inject: true,
title: `Lure${append}`,
// excludeAssets: [/style.*.js/],
excludeChunks: BLOG_VIEW_CHUNKS
.concat(STATIC_ENTRY_CHUNKS)
.filter(chunk => chunk !== chunkName),
})
const createBlogHtmlPlugin = (STATIC_ENTRY_CHUNKS, BLOG_VIEW_CHUNKS) => (
chunkName,
fileName,
title, {
author,
blogDescription,
blogTitle, blogUrl,
blogImage, blogPublishDate
},
template = addTemplateLoaders('./src/index.pug', blogUrl)
) => createHtmlPlugin(STATIC_ENTRY_CHUNKS, BLOG_VIEW_CHUNKS)(
chunkName,
fileName,
title,
template, {
blogDescription,
blogTitle,
blogImage,
blogUrl,
blogPublishDate,
author
}
)
export const createHtmlPages = (STATIC_ENTRY_CHUNKS, BLOG_VIEW_CHUNKS) => {
const createPagePlugin = createHtmlPlugin(STATIC_ENTRY_CHUNKS, BLOG_VIEW_CHUNKS)
const createBlogPlugin = createBlogHtmlPlugin(STATIC_ENTRY_CHUNKS, BLOG_VIEW_CHUNKS)
return [
createPagePlugin('home', 'index.html', ` Consulting`),
createPagePlugin('contact', 'contact.html', titleAdd('Contact')),
createPagePlugin('process', 'process.html', titleAdd('Process')),
createPagePlugin('quote', 'quote.html', titleAdd('Quote')),
createPagePlugin('blog', 'blog.html', titleAdd('Blog')),
createPagePlugin('terms-of-service', 'terms-of-service.html', titleAdd('Terms of Service')),
createPagePlugin('privacy', 'privacy-policy.html', titleAdd('Privacy Policy')),
createBlogPlugin(
'dangers-of-genservers',
'blog/elixir/dangers-of-genservers.html',
blogAdd('Dangers of GenServers'),
{
blogDescription: 'At Lure, we use the latest software to bring you the best user experience. In this article, Lure CTEO Mika Kalathil outlines some of the technical details of GenServers in Elixir, which we use to serve a large multitude of people with high speed. This is a deep dive into GenServers and discovering their limitations and strengths.',
blogTitle: 'Dangers of Genservers in Elixir',
blogImage: 'blog-elixir-dangers-of-genservers.jpeg',
blogUrl: 'blog/elixir/dangers-of-genservers',
blogPublishDate: '2018-10-29T16:14:24.526Z',
author: 'Mika Kalathil'
}
)
]
}