Add uncss

This commit is contained in:
Surinam 2020-09-13 14:32:12 +03:00
parent f5ca266050
commit 7715e3ed2d
10 changed files with 311 additions and 23 deletions

View File

@ -62,6 +62,7 @@ Options:
-o, --online [url] online url
-d, --download [url] download url
-n, --name [name] name theme
-u, --uncss removes unused CSS
-V, --version output the version number
-h, --help output usage information
```

View File

@ -2,6 +2,10 @@
const program = require('commander');
program
.storeOptionsAsProperties(true)
.passCommandToAction(false);
program
.usage('<command> [options]')
.description('Create theme for CinemaPress')
@ -15,14 +19,10 @@ program
.option('-o, --online [url]', 'online url', /^(http|https):\/\/[^ "]+$/i)
.option('-d, --download [url]', 'download url', /^(http|https):\/\/[^ "]+$/i)
.option('-n, --name [name]', 'name theme', /^[A-Za-z0-9]+$/i)
.version('0.0.11')
.option('-u, --uncss', 'removes unused CSS')
.version('0.0.12')
.parse(process.argv);
if (!program.index) {
console.error('--index required!');
process.exit();
}
require('./')(program)
.then(() => process.exit())
.catch(error => {console.error(error); process.exit()});

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 8.3 KiB

View File

@ -0,0 +1,73 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="16.000000pt" height="16.000000pt" viewBox="0 0 16.000000 16.000000"
preserveAspectRatio="xMidYMid meet">
<metadata>
Created by potrace 1.11, written by Peter Selinger 2001-2013
</metadata>
<g transform="translate(0.000000,16.000000) scale(0.003125,-0.003125)"
fill="#ffffff" stroke="none">
<path d="M2517 4984 c-1 -1 -76 -5 -167 -8 -91 -4 -178 -9 -195 -10 -119 -13
-163 -18 -185 -21 -14 -2 -45 -7 -70 -10 -470 -65 -902 -218 -1165 -413 -132
-98 -240 -232 -280 -347 -25 -69 -25 -203 0 -274 108 -322 578 -598 1240 -730
131 -26 373 -59 505 -68 197 -15 747 -7 845 11 11 2 51 7 90 11 38 4 72 8 75
10 3 2 30 6 60 10 260 32 602 133 846 250 298 142 482 310 548 500 156 453
-461 898 -1439 1039 -97 14 -182 25 -255 31 -19 2 -109 7 -200 10 -91 4 -184
8 -208 9 -24 1 -44 1 -45 0z m343 -257 c19 -3 67 -8 105 -11 39 -4 77 -9 85
-11 8 -2 38 -7 65 -10 28 -4 58 -9 67 -11 10 -3 29 -7 42 -10 142 -25 361
-101 510 -175 249 -124 379 -269 389 -434 11 -152 -68 -281 -245 -401 -68 -47
-229 -133 -264 -141 -5 -1 -40 -14 -79 -29 -59 -22 -293 -90 -318 -92 -10 0
-87 -13 -112 -18 -11 -3 -38 -7 -60 -10 -22 -3 -51 -7 -65 -10 -181 -30 -743
-23 -905 11 -11 2 -42 7 -70 10 -60 8 -240 49 -310 71 -402 126 -644 304 -690
509 -38 168 42 319 239 453 62 42 233 132 251 132 3 0 31 11 61 25 30 14 59
25 64 25 5 0 43 11 84 24 95 31 249 65 375 82 19 2 46 6 60 9 14 2 62 7 106
10 44 4 81 8 82 9 4 4 496 -3 533 -7z"/>
<path d="M2405 4647 c-185 -33 -311 -110 -317 -193 -4 -61 50 -119 152 -162
225 -95 602 -64 736 60 44 41 62 86 50 126 -11 32 -71 87 -122 111 -90 43
-191 63 -324 65 -69 1 -147 -2 -175 -7z"/>
<path d="M1558 4359 c-106 -17 -222 -62 -274 -107 -30 -26 -51 -72 -48 -105 7
-74 124 -150 278 -182 96 -19 290 -19 391 2 92 18 208 75 240 117 38 50 41 84
10 132 -42 63 -127 108 -260 136 -61 13 -273 18 -337 7z"/>
<path d="M3204 4345 c-229 -58 -319 -170 -217 -271 82 -82 236 -126 440 -125
164 1 314 41 400 107 106 81 67 191 -92 256 -99 41 -150 49 -310 53 -109 2
-145 -1 -221 -20z"/>
<path d="M2523 4129 c-84 -8 -142 -33 -163 -71 -13 -25 -13 -29 9 -52 13 -14
46 -33 72 -41 45 -15 157 -21 204 -11 66 14 125 55 125 86 0 22 -36 55 -82 74
-21 8 -38 13 -38 11 0 -2 -12 0 -27 4 -16 4 -60 4 -100 0z"/>
<path d="M1917 3914 c-105 -17 -116 -20 -178 -43 -159 -60 -208 -159 -122
-245 135 -134 528 -166 762 -61 62 28 130 91 132 123 6 66 -19 108 -85 147
-46 27 -135 60 -188 70 -81 15 -252 19 -321 9z"/>
<path d="M2961 3914 c-433 -63 -453 -325 -31 -401 14 -2 75 -6 135 -8 209 -7
387 43 463 130 18 20 33 42 33 50 1 8 2 21 3 28 3 19 -23 67 -52 95 -92 85
-350 135 -551 106z"/>
<path d="M431 3353 c0 -398 2 -416 61 -523 101 -182 303 -336 618 -473 134
-58 439 -146 625 -181 22 -4 54 -9 70 -11 30 -4 79 -12 125 -20 14 -2 56 -7
95 -11 38 -3 78 -8 89 -10 46 -9 285 -18 451 -18 172 1 443 12 454 19 4 1 38
6 76 9 39 4 79 9 90 11 11 3 37 7 58 10 82 11 116 17 202 35 50 11 101 21 115
24 75 14 298 84 405 126 347 137 579 314 675 514 16 33 34 85 40 115 13 69 12
763 -1 707 -28 -117 -136 -264 -272 -369 -181 -139 -364 -225 -702 -330 -63
-19 -355 -84 -415 -91 -25 -4 -56 -8 -70 -11 -55 -10 -200 -25 -285 -31 -49
-3 -101 -8 -115 -10 -30 -5 -456 -4 -520 1 -25 2 -81 6 -125 9 -100 8 -164 15
-285 32 -767 109 -1343 425 -1446 793 -11 40 -12 -3 -13 -316z"/>
<path d="M4682 2715 c-1 -16 -13 -55 -25 -85 -125 -304 -539 -549 -1167 -691
-47 -11 -101 -22 -120 -25 -44 -7 -88 -14 -120 -19 -89 -15 -295 -36 -405 -42
-220 -12 -676 -5 -735 12 -8 2 -44 6 -80 10 -67 6 -89 9 -200 26 -744 119
-1287 425 -1384 779 -14 51 -15 29 -13 -325 2 -337 4 -385 20 -428 80 -215
300 -401 647 -549 115 -49 372 -132 470 -152 241 -48 316 -61 420 -72 25 -2
56 -6 70 -9 101 -19 692 -28 880 -12 84 7 387 48 463 62 45 9 199 45 237 55
116 32 223 66 280 87 249 95 450 213 580 343 94 93 141 169 179 290 6 20 13
603 9 700 -2 41 -5 62 -6 45z"/>
<path d="M4682 1733 c-14 -136 -158 -323 -343 -445 -160 -107 -381 -207 -589
-266 -144 -42 -187 -53 -280 -72 -58 -12 -121 -24 -140 -26 -19 -2 -57 -9 -85
-14 -27 -5 -77 -12 -110 -16 -33 -3 -69 -8 -80 -10 -130 -25 -941 -24 -985 0
-3 2 -39 7 -80 10 -41 4 -82 9 -90 11 -16 4 -70 13 -130 21 -152 20 -501 120
-670 192 -348 147 -582 348 -646 555 -9 29 -18 57 -19 62 -2 6 -3 -161 -2
-370 l2 -380 25 -60 c68 -161 204 -298 415 -421 80 -47 221 -114 239 -114 7 0
16 -4 21 -9 16 -16 212 -80 354 -117 127 -33 343 -76 444 -88 26 -3 66 -8 90
-11 214 -27 592 -36 837 -21 117 7 143 10 240 22 30 4 66 8 80 9 23 2 89 12
135 21 11 2 40 7 65 10 25 3 48 8 53 11 4 2 20 7 35 9 115 20 326 80 458 130
417 156 687 380 749 620 13 50 15 122 12 420 -1 197 -3 349 -5 337z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

@ -31,7 +31,7 @@
<% /* Изображение новости */ %>
<% if (content.image) { %>
<img src="<%- content.image %>" class="cinemapress-content-image">
<img src="<%- content.image %>" class="cinemapress-content-image" alt="Image">
<% } %>
<% /* Описание новости */ %>

View File

@ -14,10 +14,10 @@
<a href="<%- page.social.vk %>" target="_blank"><%- page.l.vk %></a>
<% } %>
<% if (page.social.facebook) { %>
<a href="<%- page.social.facebook %>" target="_blank">facebook</a>
<a href="<%- page.social.facebook %>" target="_blank"><%- page.l.facebook %></a>
<% } %>
<% if (page.social.twitter) { %>
<a href="<%- page.social.twitter %>" target="_blank">twitter</a>
<a href="<%- page.social.twitter %>" target="_blank"><%- page.l.twitter %></a>
<% } %>
<% if (page.social.youtube) { %>
<a href="<%- page.social.youtube %>" target="_blank"><%- page.l.youtube %></a>

View File

@ -109,6 +109,10 @@
<% if (movie.imdb_vote) { %>
<%- page.l.rating %>: <%- movie.imdb_rating %> (<%- movie.imdb_vote %> <%- page.l.votes %>)
<% } %>
<% /* Список тегов */ %>
<% if (movie.tags_url) { %>
<%- page.l.tags %>: <%- movie.tags_url %>
<% } %>
<% /* Вышел на экраны или нет */ %>
<% if (movie.passed) { %>Премьера состоялась<% } %>
<% /* Дата премьеры фильма */ %>

View File

@ -4,11 +4,29 @@ module.exports = parameters => {
const spinner = ora('Loading ...').start();
return Promise.resolve(parameters)
.then(require('./lib/scraper'))
.then(require('./lib/codes'))
.then(r => {
spinner.succeed('Success!');
return r;
});
if (typeof parameters.index === 'undefined') {
spinner.warn('--index required!');
return Promise.resolve();
}
if (typeof parameters.uncss === 'undefined') {
return Promise.resolve(parameters)
.then(require('./lib/scraper'))
.then(require('./lib/codes'))
.then(r => {
spinner.succeed('Success!');
return r;
});
} else {
if (typeof parameters.name === 'undefined' || typeof parameters.movie === 'undefined' || typeof parameters.category === 'undefined' || typeof parameters.categories === 'undefined') {
spinner.warn('--name --movie --category --categories required!');
return Promise.resolve();
}
return Promise.resolve(parameters)
.then(require('./lib/uncss'))
.then(r => {
spinner.succeed('Success!');
return r;
});
}
};

123
lib/uncss.js Normal file
View File

@ -0,0 +1,123 @@
const uncss = require('uncss');
const path = require('path');
const axios = require('axios');
const util = require('util');
const { readdirSync, writeFile, writeFileSync, existsSync, unlinkSync } = require('fs');
const u = util.promisify(uncss);
const w = util.promisify(writeFile);
module.exports = parameters => {
const getDirectories = source =>
readdirSync(source, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name);
const getFiles = source =>
readdirSync(source, { withFileTypes: true })
.filter(dirent => dirent.isFile())
.map(dirent => dirent.name);
function getIndex() {
return axios.get(parameters.index);
}
function getMovie() {
return axios.get(parameters.movie);
}
function getCategory() {
return axios.get(parameters.category);
}
function getCategories() {
return axios.get(parameters.categories);
}
let urls = [];
let index_html = '';
let movie_html = '';
let category_html = '';
let categories_html = '';
let htmlroot = '';
let home = '';
let themes = '';
let theme = '';
let all = '';
if (existsSync(path.join('/home'))) {
home = path.join('/home');
let home_list = getDirectories(home);
(home_list || []).forEach(function (website) {
if (existsSync(path.join(home, website, 'themes'))) {
themes = path.join(home, website, 'themes');
if (existsSync(path.join(themes, parameters.name))) {
theme = path.join(themes, parameters.name);
htmlroot = path.join(home, website);
all = path.join(theme, 'public', 'css', 'all.css');
}
}
});
}
return Promise.all([getIndex(), getMovie(), getCategory(), getCategories()])
.then(function (results) {
const [index, movie, category, categories] = results;
if (index && index.data) {
index_html = path.join(theme, 'index.html');
writeFileSync(index_html, index.data.replace(/\.(js|css)\?v=[a-z0-9]*/ig, '.$1').replace(/<script(?:(?!\/\/)(?!\/\*)[^'"]|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\/\/.*(?:\n)|\/\*(?:(?:.|\s))*?\*\/)*?<\/script>/ims, ''));
urls.push(index_html);
}
if (movie && movie.data) {
movie_html = path.join(theme, 'movie.html');
writeFileSync(movie_html, movie.data.replace(/\.(js|css)\?v=[a-z0-9]*/ig, '.$1').replace(/<script(?:(?!\/\/)(?!\/\*)[^'"]|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\/\/.*(?:\n)|\/\*(?:(?:.|\s))*?\*\/)*?<\/script>/ims, ''));
urls.push(movie_html);
}
if (category && category.data) {
category_html = path.join(theme, 'category.html');
writeFileSync(category_html, category.data.replace(/\.(js|css)\?v=[a-z0-9]*/ig, '.$1').replace(/<script(?:(?!\/\/)(?!\/\*)[^'"]|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\/\/.*(?:\n)|\/\*(?:(?:.|\s))*?\*\/)*?<\/script>/ims, ''));
urls.push(category_html);
}
if (categories && categories.data) {
categories_html = path.join(theme, 'categories.html');
writeFileSync(movie_html, categories.data.replace(/\.(js|css)\?v=[a-z0-9]*/ig, '.$1').replace(/<script(?:(?!\/\/)(?!\/\*)[^'"]|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\/\/.*(?:\n)|\/\*(?:(?:.|\s))*?\*\/)*?<\/script>/ims, ''));
urls.push(categories_html);
}
})
.then(function () {
urls = urls.filter(Boolean);
let options = {
htmlroot : htmlroot,
jsdom : {
userAgent: 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4230.1 Safari/537.36',
},
timeout : 1000,
report : false,
strictSSL : false,
userAgent : 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4230.1 Safari/537.36',
};
return u(urls, options)
.then(output => {
return w(all, output)
.then(res => {
unlinkSync(index_html);
unlinkSync(movie_html);
unlinkSync(category_html);
unlinkSync(categories_html);
return Promise.resolve();
})
.catch(err => {
console.error(err);
});
})
.catch(err => {
console.error(err);
});
})
.then(function () {
return true;
});
};

View File

@ -1,6 +1,6 @@
{
"name": "cinematheme",
"version": "0.0.11",
"version": "0.0.12",
"description": "Create theme for CinemaPress",
"main": "index.js",
"license": "MIT",
@ -16,11 +16,13 @@
},
"homepage": "https://github.com/CinemaPress",
"dependencies": {
"ora": "4.0.4",
"jsdom": "16.2.2",
"commander": "4.1.1",
"fs-extra": "8.1.0",
"js-beautify": "1.11.0",
"website-scraper": "4.2.1"
"ora": "5.1.0",
"jsdom": "16.4.0",
"commander": "6.1.0",
"fs-extra": "9.0.1",
"js-beautify": "1.13.0",
"website-scraper": "4.2.2",
"uncss": "0.17.3",
"axios": "0.20.0"
}
}