1
1
require ( "dotenv" ) . config ( ) ;
2
2
3
- const cleanCSS = require ( "clean-css" ) ;
3
+ // const cleanCSS = require("clean-css");
4
4
const fs = require ( "fs" ) ;
5
5
const pluginRSS = require ( "@11ty/eleventy-plugin-rss" ) ;
6
- const localImages = require ( "eleventy-plugin-local-images" ) ;
7
- const lazyImages = require ( "eleventy-plugin-lazyimages" ) ;
6
+ // const localImages = require("eleventy-plugin-local-images");
7
+ // const lazyImages = require("eleventy-plugin-lazyimages");
8
8
const ghostContentAPI = require ( "@tryghost/content-api" ) ;
9
9
10
- const htmlMinTransform = require ( "./src/transforms/html-min-transform.js" ) ;
10
+ // const htmlMinTransform = require("./src/transforms/html-min-transform.js");
11
11
12
12
// Init Ghost API
13
13
const api = new ghostContentAPI ( {
@@ -23,29 +23,29 @@ const stripDomain = url => {
23
23
24
24
module . exports = function ( config ) {
25
25
// Minify HTML
26
- config . addTransform ( "htmlmin" , htmlMinTransform ) ;
26
+ // config.addTransform("htmlmin", htmlMinTransform);
27
27
28
28
// Assist RSS feed template
29
29
config . addPlugin ( pluginRSS ) ;
30
30
31
31
// Apply performance attributes to images
32
- config . addPlugin ( lazyImages , {
33
- cacheFile : ""
34
- } ) ;
32
+ // config.addPlugin(lazyImages, {
33
+ // cacheFile: ""
34
+ // });
35
35
36
36
// Copy images over from Ghost
37
- config . addPlugin ( localImages , {
38
- distPath : "dist" ,
39
- assetPath : "/assets/images" ,
40
- selector : "img" ,
41
- attribute : "data-src" , // Lazy images attribute
42
- verbose : false
43
- } ) ;
37
+ // config.addPlugin(localImages, {
38
+ // distPath: "dist",
39
+ // assetPath: "/assets/images",
40
+ // selector: "img",
41
+ // attribute: "data-src", // Lazy images attribute
42
+ // verbose: false
43
+ // });
44
44
45
45
// Inline CSS
46
- config . addFilter ( "cssmin" , code => {
47
- return new cleanCSS ( { } ) . minify ( code ) . styles ;
48
- } ) ;
46
+ // config.addFilter("cssmin", code => {
47
+ // return new cleanCSS({}).minify(code).styles;
48
+ // });
49
49
50
50
config . addFilter ( "getReadingTime" , text => {
51
51
const wordsPerMinute = 200 ;
@@ -84,6 +84,8 @@ module.exports = function(config) {
84
84
85
85
return collection ;
86
86
} ) ;
87
+
88
+
87
89
88
90
// Get all posts
89
91
config . addCollection ( "posts" , async function ( collection ) {
@@ -97,12 +99,22 @@ module.exports = function(config) {
97
99
} ) ;
98
100
99
101
collection . forEach ( post => {
100
- post . url = stripDomain ( post . url ) ;
101
102
post . primary_author . url = stripDomain ( post . primary_author . url ) ;
102
103
post . tags . map ( tag => ( tag . url = stripDomain ( tag . url ) ) ) ;
103
104
104
105
// Convert publish date into a Date object
105
106
post . published_at = new Date ( post . published_at ) ;
107
+
108
+ var MyDate = post . published_at ;
109
+ var MyDateString ;
110
+
111
+ MyDate . setDate ( MyDate . getDate ( ) ) ;
112
+
113
+ MyDateString = MyDate . getFullYear ( ) + "/" + ( '0' + ( MyDate . getMonth ( ) + 1 ) ) . slice ( - 2 ) ;
114
+
115
+ post . url = "/" + MyDateString + stripDomain ( post . url ) ;
116
+
117
+
106
118
} ) ;
107
119
108
120
// Bring featured post to the top of the list
@@ -111,89 +123,89 @@ module.exports = function(config) {
111
123
return collection ;
112
124
} ) ;
113
125
114
- // Get all authors
115
- config . addCollection ( "authors" , async function ( collection ) {
116
- collection = await api . authors
117
- . browse ( {
118
- limit : "all"
119
- } )
120
- . catch ( err => {
121
- console . error ( err ) ;
122
- } ) ;
123
-
124
- // Get all posts with their authors attached
125
- const posts = await api . posts
126
- . browse ( {
127
- include : "authors" ,
128
- limit : "all"
129
- } )
130
- . catch ( err => {
131
- console . error ( err ) ;
132
- } ) ;
133
-
134
- // Attach posts to their respective authors
135
- collection . forEach ( async author => {
136
- const authorsPosts = posts . filter ( post => {
137
- post . url = stripDomain ( post . url ) ;
138
- return post . primary_author . id === author . id ;
139
- } ) ;
140
- if ( authorsPosts . length ) author . posts = authorsPosts ;
141
-
142
- author . url = stripDomain ( author . url ) ;
143
- } ) ;
144
-
145
- return collection ;
146
- } ) ;
126
+ // // Get all authors
127
+ // config.addCollection("authors", async function(collection) {
128
+ // collection = await api.authors
129
+ // .browse({
130
+ // limit: "all"
131
+ // })
132
+ // .catch(err => {
133
+ // console.error(err);
134
+ // });
135
+ //
136
+ // // Get all posts with their authors attached
137
+ // const posts = await api.posts
138
+ // .browse({
139
+ // include: "authors",
140
+ // limit: "all"
141
+ // })
142
+ // .catch(err => {
143
+ // console.error(err);
144
+ // });
145
+ //
146
+ // // Attach posts to their respective authors
147
+ // collection.forEach(async author => {
148
+ // const authorsPosts = posts.filter(post => {
149
+ // post.url = stripDomain(post.url);
150
+ // return post.primary_author.id === author.id;
151
+ // });
152
+ // if (authorsPosts.length) author.posts = authorsPosts;
153
+ //
154
+ // author.url = stripDomain(author.url);
155
+ // });
156
+ //
157
+ // return collection;
158
+ // });
147
159
148
160
// Get all tags
149
- config . addCollection ( "tags" , async function ( collection ) {
150
- collection = await api . tags
151
- . browse ( {
152
- include : "count.posts" ,
153
- limit : "all"
154
- } )
155
- . catch ( err => {
156
- console . error ( err ) ;
157
- } ) ;
158
-
159
- // Get all posts with their tags attached
160
- const posts = await api . posts
161
- . browse ( {
162
- include : "tags,authors" ,
163
- limit : "all"
164
- } )
165
- . catch ( err => {
166
- console . error ( err ) ;
167
- } ) ;
168
-
169
- // Attach posts to their respective tags
170
- collection . forEach ( async tag => {
171
- const taggedPosts = posts . filter ( post => {
172
- post . url = stripDomain ( post . url ) ;
173
- return post . primary_tag && post . primary_tag . slug === tag . slug ;
174
- } ) ;
175
- if ( taggedPosts . length ) tag . posts = taggedPosts ;
176
-
177
- tag . url = stripDomain ( tag . url ) ;
178
- } ) ;
179
-
180
- return collection ;
181
- } ) ;
161
+ // config.addCollection("tags", async function(collection) {
162
+ // collection = await api.tags
163
+ // .browse({
164
+ // include: "count.posts",
165
+ // limit: "all"
166
+ // })
167
+ // .catch(err => {
168
+ // console.error(err);
169
+ // });
170
+ //
171
+ // // Get all posts with their tags attached
172
+ // // const posts = await api.posts
173
+ // // .browse({
174
+ // // include: "tags,authors",
175
+ // // limit: "all"
176
+ // / / })
177
+ // // .catch(err => {
178
+ // // console.error(err);
179
+ // / / });
180
+ //
181
+ // // Attach posts to their respective tags
182
+ // // collection.forEach(async tag => {
183
+ // // const taggedPosts = posts.filter(post => {
184
+ // // post.url = stripDomain(post.url);
185
+ // // return post.primary_tag && post.primary_tag.slug === tag.slug;
186
+ // / / });
187
+ // // if (taggedPosts.length) tag.posts = taggedPosts;
188
+ // //
189
+ // // tag.url = stripDomain(tag.url);
190
+ // / / });
191
+ //
192
+ // return collection;
193
+ // });
182
194
183
195
// Display 404 page in BrowserSnyc
184
- config . setBrowserSyncConfig ( {
185
- callbacks : {
186
- ready : ( err , bs ) => {
187
- const content_404 = fs . readFileSync ( "dist/404.html" ) ;
188
-
189
- bs . addMiddleware ( "*" , ( req , res ) => {
190
- // Provides the 404 content without redirect.
191
- res . write ( content_404 ) ;
192
- res . end ( ) ;
193
- } ) ;
194
- }
195
- }
196
- } ) ;
196
+ // config.setBrowserSyncConfig({
197
+ // callbacks: {
198
+ // ready: (err, bs) => {
199
+ // const content_404 = fs.readFileSync("dist/404.html");
200
+ //
201
+ // bs.addMiddleware("*", (req, res) => {
202
+ // // Provides the 404 content without redirect.
203
+ // res.write(content_404);
204
+ // res.end();
205
+ // });
206
+ // }
207
+ // }
208
+ // });
197
209
198
210
// Eleventy configuration
199
211
return {
0 commit comments