Last active
January 5, 2022 12:56
-
-
Save saippuakauppias/71c62af551ac7cd5c51a217cff97c882 to your computer and use it in GitHub Desktop.
Beautify & Tidy cloned html template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$html_content = get_content_by_pattern(__DIR__ . '/template/index_beautify.htm*'); | |
//$html_content .= get_content_by_pattern(__DIR__ . '/template/errors/*.twig'); | |
$css_content = get_content_by_pattern(__DIR__ . '/template/index_files/tidy.max.cs*'); | |
$html_content = preg_replace('#\{\{[^\}]+\}\}#iUs', '', $html_content); | |
$html_content = preg_replace('#\{%[^\}%]+%\}#iUs', '', $html_content); | |
preg_match_all('#class=["\']{1}([^"\']+)["\']{1}#iUs', $html_content, $matches); | |
$selectors = []; | |
foreach($matches[1] as $class_attrs) { | |
$selectors = array_merge($selectors, explode(' ', $class_attrs)); | |
} | |
$selectors = array_filter($selectors); | |
$selectors = array_unique($selectors); | |
foreach ($selectors as $css_sel) { | |
if (strpos($css_content, $css_sel) === false) { | |
echo $css_sel . PHP_EOL; | |
} | |
} | |
function get_content_by_pattern($pattern) { | |
$files = glob($pattern); | |
$content = ''; | |
foreach ($files as $file_path) { | |
$content .= file_get_contents($file_path) . PHP_EOL; | |
} | |
return $content; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (grunt) { | |
// original: https://www.keycdn.com/blog/remove-unused-css | |
grunt.initConfig({ | |
uncss: { | |
dist: { | |
files: [ | |
{ src: 'template/index.html', dest: 'template/index_files/tidy.css' } | |
] | |
} | |
} | |
}); | |
// Load the plugins | |
grunt.loadNpmTasks('grunt-uncss'); | |
// Default tasks. | |
grunt.registerTask('default', ['uncss']); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var rename = require('gulp-rename'); | |
var cssbeautify = require('gulp-cssbeautify'); | |
var beautify = require('gulp-beautify'); | |
var removeEmptyLines = require('gulp-remove-empty-lines'); | |
gulp.task('beautify_css', function() { | |
return gulp.src('template/index_files/tidy.css') | |
.pipe(cssbeautify()) | |
.pipe(rename({ | |
basename: 'tidy.max' | |
})) | |
.pipe(gulp.dest('template/index_files')); | |
}); | |
gulp.task('beautify_html', function() { | |
return gulp.src('template/*.html') | |
.pipe(beautify.html({ indent_size: 4 })) | |
.pipe(removeEmptyLines()) | |
.pipe(rename({ | |
basename: 'index_beautify' | |
})) | |
.pipe(gulp.dest('kanopy')); | |
}); | |
gulp.task('default', ['beautify_css', 'beautify_html']); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"devDependencies": { | |
"grunt": "^1.0.3", | |
"grunt-cli": "^1.3.2", | |
"grunt-uncss": "^0.8.5", | |
"gulp": "^3.9.1", | |
"gulp-concat": "^2.6.1", | |
"gulp-cssbeautify": "^1.0.1", | |
"gulp-rename": "^1.4.0", | |
"gulp-beautify": "^3.0.0", | |
"gulp-remove-empty-lines": "^0.1.0" | |
} | |
} |
Author
saippuakauppias
commented
Mar 23, 2019
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment