Skip to content

Commit d54f7df

Browse files
committed
Add basic AMP support
Signed-off-by: Yen-Chin Lee <[email protected]>
1 parent 2d203c1 commit d54f7df

File tree

10 files changed

+388
-97
lines changed

10 files changed

+388
-97
lines changed

.bowerrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"directory": "bower_components"
3+
}

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ pom.xml.asc
1010
.lein-plugins/
1111
.lein-failures
1212
/resources/public/
13-
.gh-pages/
13+
.gh-pages/
14+
/bower_components/
15+
/node_modules/
16+
/build/

bower.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "clojuretw-weekly",
3+
"version": "1.0.0",
4+
"homepage": "https://github.com/clojure-tw/weekly",
5+
"author": "Yen-Chin, Lee",
6+
"keywords": [
7+
"clojure",
8+
"amp"
9+
],
10+
"license": "CC0",
11+
"ignore": [
12+
"**/.*",
13+
"node_modules",
14+
"bower_components"
15+
],
16+
"dependencies": {
17+
"bootstrap": "3.3.0"
18+
}
19+
}

circle.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies:
1414
- chmod 755 lein
1515
- ./lein -v
1616
- ./lein deps
17-
- npm install -g html-minifier
17+
- npm install
1818
cache_directories:
1919
- ~/.m2
2020
- ~/.lein

deploy.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ rm -rf $OUT || exit 0;
1414
# create repo directory
1515
mkdir $OUT
1616

17+
# build with amp support by gulp
18+
./node_modules/gulp/bin/gulp.js
19+
1720
# Copy all prebuild files, if html-minifer exist, use it to minify html content
18-
cp -R resources/public/weekly/* $OUT
21+
cp -R ./build/dist/* $OUT
1922
cp -f circle.yml $OUT
2023
if hash html-minifier; then
2124
html-minifier --input-dir $OUT --output-dir $OUT --collapse-whitespace --file-ext html

gulpfile.js

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
"use strict";
2+
3+
const gulp = require('gulp-help')(require('gulp'));
4+
const bower = require('gulp-bower');
5+
const purify = require('gulp-purifycss');
6+
const concatCss = require('gulp-concat-css');
7+
const cleanCSS = require('gulp-clean-css');
8+
const gulpIgnore = require('gulp-ignore');
9+
const htmlreplace = require('gulp-html-replace');
10+
const gulpRemoveHtml = require('gulp-remove-html');
11+
const htmlmin = require('gulp-html-minifier');
12+
const gulpAmpValidator = require('gulp-amphtml-validator');
13+
const replace = require('gulp-replace');
14+
const uncss = require('gulp-uncss');
15+
16+
const paths = {
17+
src: {
18+
dir: './resources/public/weekly',
19+
html: './resources/public/weekly/**/*.html'
20+
},
21+
dist: {
22+
dir: './build/dist',
23+
html: './build/dist/**/*.html'
24+
},
25+
tmp: {
26+
dir: './build/tmp',
27+
css: './build/tmp/app.css'
28+
}
29+
};
30+
31+
gulp.task('compile:css', function() {
32+
return gulp.src(['./bower_components/bootstrap/dist/css/bootstrap.min.css',
33+
'./resources/public/weekly/css/screen.css'])
34+
.pipe(concatCss('app.css'))
35+
.pipe(purify([paths.src.html]))
36+
// remove !importent which not supported by amphtml
37+
.pipe(replace(/!important/g, ''))
38+
// remove @-ms-viewport which not supported by amphtml
39+
.pipe(replace(/@-ms-viewport\s*{\n(.*?)\n}/g, ''))
40+
.pipe(gulp.dest(paths.tmp.dir));
41+
});
42+
43+
// inline-css inserts the cleaned + minified CSS into HTML
44+
gulp.task('build:inline-css', ['compile:css'], function() {
45+
return gulp.src(paths.src.html)
46+
.pipe(htmlreplace({
47+
'cssInline': {
48+
'src': gulp.src(paths.tmp.css).pipe(cleanCSS()),
49+
'tpl': '<style amp-custom>%s</style>'
50+
}
51+
}))
52+
.pipe(gulp.dest(paths.dist.dir));
53+
});
54+
55+
gulp.task('build:remove-html', ['build:inline-css'], function () {
56+
return gulp.src(paths.dist.html)
57+
.pipe(gulpRemoveHtml({
58+
'keyword': 'build:removeHtml'
59+
}))
60+
.pipe(gulp.dest(paths.dist.dir));
61+
});
62+
63+
gulp.task('build:minify-html', ['build:remove-html'], function() {
64+
return gulp.src(paths.dist.html)
65+
.pipe(htmlmin({collapseWhitespace: true,
66+
minifyJS: true,
67+
minifyCSS: true,
68+
removeComments: true}))
69+
.pipe(gulp.dest(paths.dist.dir));
70+
});
71+
72+
gulp.task('bower', function() {
73+
return bower();
74+
});
75+
76+
gulp.task('validate:amphtml', ['build:minify-html'], function() {
77+
//gulp.task('validate:amphtml', function() {
78+
return gulp.src(paths.dist.html)
79+
// Some page no need to support amp, just ignore it
80+
.pipe(gulpIgnore.exclude(['**/404.html']))
81+
// Valide the input and attach the validation result to the "amp" property
82+
// of the file object.
83+
.pipe(gulpAmpValidator.validate())
84+
// Print the validation results to the console.
85+
.pipe(gulpAmpValidator.format())
86+
// Exit the process with error code (1) if an AMP validation error
87+
// occurred.
88+
.pipe(gulpAmpValidator.failAfterError());
89+
});
90+
91+
gulp.task('build', 'build all resources', [
92+
'bower',
93+
'compile:css',
94+
'build:inline-css',
95+
'build:remove-html',
96+
'build:minify-html',
97+
'validate:amphtml'
98+
]);
99+
100+
gulp.task('default', 'build all resources', [
101+
'build',
102+
]);

package.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "clojuretw-weekly",
3+
"version": "1.0.0",
4+
"description": "Weekly news for Clojure Taiwan Community",
5+
"keywords": [
6+
"clojure",
7+
"amp"
8+
],
9+
"author": "Yen-Chin, Lee",
10+
"license": "CC0",
11+
"devDependencies": {
12+
"gulp": "^3.9.1",
13+
"gulp-amphtml-validator": "^1.0.0",
14+
"gulp-bower": "0.0.13",
15+
"gulp-clean-css": "^2.0.12",
16+
"gulp-concat-css": "^2.3.0",
17+
"gulp-help": "^1.6.1",
18+
"gulp-html-minifier": "^0.1.8",
19+
"gulp-html-replace": "^1.6.1",
20+
"gulp-ignore": "^2.0.2",
21+
"gulp-purifycss": "^0.2.0",
22+
"gulp-remove-html": "^1.3.0",
23+
"gulp-replace": "^0.5.4",
24+
"gulp-uncss": "^1.0.6",
25+
"purifycss": "^1.1.9"
26+
},
27+
"dependencies": {
28+
"bower": "^1.8.0"
29+
}
30+
}

project.clj

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
:plugins [[lein-ring "0.9.7"]]
1313
:main cryogen.core
1414
:ring {:init cryogen.server/init
15-
:handler cryogen.server/handler})
15+
:handler cryogen.server/handler}
16+
:aliases {"gulp" ["do" ["shell" "node_modules/.bin/gulp" "default"]]})

resources/templates/themes/clojuretw/css/screen.css

+101
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,30 @@ a:hover {
8181
background-color: #fff;
8282
}
8383

84+
.navbar .hamburger {
85+
background-color: transparent;
86+
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="-3 -6 24 24"><path fill="#4A4A4A" d="M0 12h18v-2H0v2M0 7h18V5H0v2M0 0v2h18V0H0"/></svg>');
87+
background-repeat: no-repeat;
88+
background-size: 30px 24px;
89+
background-position: center center;
90+
border: none;
91+
margin: 0;
92+
padding: 0;
93+
width: 40px;
94+
height: 40px;
95+
display: none;
96+
cursor: pointer;
97+
-ms-flex-item-align: center;
98+
-ms-grid-row-align: center;
99+
align-self: center;
100+
}
101+
102+
/* @media only screen and (max-width: 956px) { */
103+
/* .navbar .hamburger { */
104+
/* display: inline-block */
105+
/* } */
106+
/* } */
107+
84108
#sidebar {
85109
margin-left: 15px;
86110
margin-top: 50px;
@@ -179,8 +203,85 @@ pre, code, .hljs {
179203
float:left;
180204
text-align: left;
181205
}
206+
.navbar .hamburger {
207+
display: inline-block
208+
}
182209
}
183210

184211
ul li {
185212
margin:0 0 10px 0;
186213
}
214+
215+
/* footer */
216+
footer p {
217+
text-align: center;
218+
}
219+
220+
/* amp-sidebar */
221+
amp-sidebar {
222+
width: 180px;
223+
background: #fff;
224+
min-width: 80vw;
225+
}
226+
227+
amp-sidebar nav ul {
228+
padding-right: 0;
229+
background: #fff
230+
}
231+
amp-sidebar nav ul li {
232+
list-style: none;
233+
margin-bottom: 0
234+
}
235+
amp-sidebar nav ul li ul {
236+
margin-left: 12px;
237+
margin-bottom: 0
238+
}
239+
amp-sidebar nav ul li ul li {
240+
list-style: none;
241+
margin: 0
242+
}
243+
amp-sidebar nav ul li ul li a {
244+
padding: 6px 15px;
245+
font-size: 1.2em
246+
}
247+
amp-sidebar nav a,
248+
amp-sidebar nav span,
249+
amp-sidebar nav h2 {
250+
color: #424242;
251+
text-transform: uppercase;
252+
font-weight: 400;
253+
display: block;
254+
padding: 6px 12px;
255+
letter-spacing: 0.04em;
256+
font-size: 15px
257+
}
258+
amp-sidebar nav nav {
259+
background: #1e879e;
260+
box-sizing: border-box
261+
}
262+
amp-sidebar nav nav h2 {
263+
font-style: italic;
264+
margin-bottom: 0
265+
}
266+
amp-sidebar nav nav li {
267+
font-size: 14px
268+
}
269+
amp-sidebar nav nav li ul li.current {
270+
position: relative
271+
}
272+
amp-sidebar nav nav li ul li.current span {
273+
color: #0379C4;
274+
font-weight: 400
275+
}
276+
amp-sidebar nav nav li ul li.current ul {
277+
border-top: 0;
278+
margin-top: 0;
279+
padding-top: 0;
280+
padding-left: 12px
281+
}
282+
amp-sidebar nav nav li ul li.current::after {
283+
left: -12px
284+
}
285+
amp-sidebar nav nav li ul li a {
286+
font-size: 1em
287+
}

0 commit comments

Comments
 (0)