For a while now, i’ve used the JSON api to get a list of all page urls as a json file for use with Uncss, but the main drawback with my approach is the necessary dummy article. I followed the advice in the cookbook originally and tweaked the page code in the cookbook for compatibility with the Uncss postcss plugin:
<?php
header('Content-type: application/json; charset=utf-8');
$root = $site->find('home');
$firstlevel = $site->children()->visible();
$secondlevel = $site->children()->children()->visible();
$thirdlevel = $site->children()->children()->children()->visible();
$json = array();
$json[] = (string)$root->url();
foreach ($firstlevel as $article) {
$json[] = (string)$article->url();
}
foreach ($secondlevel as $article) {
$json[] = (string)$article->url();
}
foreach ($thirdlevel as $article) {
$json[] = (string)$article->url();
}
echo json_encode($json);
Essentially, I grab the JSON to a file in my projects root by hitting domain.com/uncss with curl
on the command line via an NPM script, then pump this into PostCss.
But what i don’t like is the uncss content article in the content folder because clients always say whats that??? i just have to say leave it alone, don’t delete it.
Is there a way to do this without having to have that dummy content folder just the make the url work? Is there a more Ninja way?