html-minifier: Recursive but copying-over invalid files - html

I first met html-minifier today after running a small site I've created using Hugo through Google PageSpeed.
First thing I noticed is that although it does have recursion capabilities it stops working on unsupported files like images (my speakers started beeping and I freaked a little)
I've found this stack showing an apparently undocumented command-line option --file-ext
That worked perfectly but in the output directory, I noticed that the folders with the unmatching contents were gone.
From the directory root, I saw it was Hugo's folders for CSS, JS, images and Github Pages' CNAME file. Not only I can't tell for sure there's not even one piece of static file in any of the folders Hugo generated (you may know that Hugo is sometimes unpredictable) but also I would like to keep language specific XML Sitemaps I've created for some specific folders.
Long story short, is there a way to copy-over unmatching files "as is", keeping input directory ready for a commit/push?

After analyzing the whole directory structure I could be sure that within all the directory structure Hugo creates there are nothing more than HTML and XML files so then the Ockham's Razor took place.
Since both my Hugo's source code and output contents are in totally different directories, it was a simple matter of pointing the output directory to the same path of the input directory.
All HTML files are minified, overwriting those Hugo generated.

Related

Flutter render downloaded html

I have an elearning APP in Flutter, which can render html files stored online. Now I want to download these files to assets, so they may be accessed offline. For this, I will download a zipped file with the entire html's folder and unzip it.
The problem is the html has many subfolders with it's own assets, which I would have to declare in the pubsp.yaml in order to access, but these downloadable htmls are constantly being added (every new course has new files).
I see a few ways to solve the problem:
Somehow declare access to subfolders in the pubsp.yaml.
As far as I know, this cannot be done.
Update the folder access for the installed APP dynamically.
As far as I know, this cannot be done.
Read the html file without unziping it.
I don't know if this is doable (I'm using webview_flutter_plus to render) and weather it would allow access to files in folders inside the zip without declaring them in the .yaml.
Pre-load empty folders inside assets that would mimic the html folder structure, declare them in the .yaml and then unzip and read the htmls from these folders. I would create some 100 of them in order to accomodate a large number of course downloads.
I believe this method would work, but it seems very cumbersome and inelegant.
So my questions are:
Would any of methods 1-3 work and if so how?
Would method 4 work?
Is it possible to reference folders in the .yaml file without them existing? It would make method 4 far easier.
Is there any other way to accomplish this? I cannot change the language, since the APP is months along, but plugins are fair game.
Thanks in advance!

Can I compile with electron-build and keep my html files?

I'm using electron-build to transform a "website" into an "app" and it's pretty awesome! But the compilation process obviously transforms the HTML pages into other types of files.
Is there any compilation option, flag or anything that can allow me to keep the html files and resources so that a curious user can click on index.html and use the app in their favorite web browser?
I havent found anything, so I'm considering simply copy pasting the source files in the output folder, but that's a lot of duplicate data :)
Thanks!

Adding non-text files to `_posts` in Jekyll

Short story: I want to be able to store non-text files/directories in the _posts/ folder.
This is not about local assets, or anything like that. I literally just want to store files (non-associated images and directories) there for a specific, unrelated issue that doesn't merit discussion.
Is there a way to put a folder in _posts/ and in essence have Jekyll ignore all of its contents? Or at least, not freak out about the contents being non-text files?
EDIT: It seems that the actual errors are coming from the names of some of the sub-subdirectories. When the name of these directories start with a date, it gives me the error:
Liquid Exception: invalid byte sequence in UTF-8 in /Users/burchill/burchill.github.io/_posts/blah/source/2017-1‌​0-28-blahblah_post/b‌​lah.png
EDIT #2: After changing the directory names to "play nice" with Jekyll's regex, Jekyll no longer gives an error, but when I try to link to these images on my posts, they don't show up, unlike files in other non-_posts directories.
Jekyll won't process files not starting with the triple dashes block (frontmatter) so it is safe to have any other file in your _posts folder.
https://jekyllrb.com/docs/frontmatter/

PhpStorm virtual file splitting

I can't find a more appropriate. I'm using PhpStorm to create web content (php, html, css, js..) and I'm facing the problem of long files (not even so long few hundred lines enough to be lost) where it gets hard to find things and remove unnecessary content.
I was wondering if there is a functionality, plugin or external file manager where it creates different files from one file on disk.
For example: when we have a .css file, for sure it's content is dealing with different features/parts of the html but they are all on the same html page. So it's a bad idea to create different .css file for each part, but it would be nice to have different virtual files for each part/feature where we can code and debug separately our code; but they are saved to same file.
Lets say:
common_header.css: deals with headers
common_menu.css: deals with menu (some menu we have on our page)
common_footer.css: deals with what ever to the end of page
... and so on
So now while coding we see different files (best as a subtree of the original file) some thing like that on file manager:
....other file // the dot here should be + since subtree hidden
common.css // the dot here should be - since subtree is shown
common_header.css
common_menu.css
common_footer.css
...
....other file
But when on disk they are all on the same file common.css that is loaded to our browser as one too.
If your target is to reduce the number of files being loaded from your server, after the application has been deployed, you might merge and compress your files as shown here.
In case you don't want to waste computing time to compress the files on each call, you could adjust your build process to generate them once during build (something like minify).

customizing `org-publish-project-alist`

I'm trying to publish webpage using org-mode. Two questions:
Is there a way to "sync" the org-mode files in the base-directory and the html files in the publishing-directory? Specifically, if I delete an org file in the base-directory, can I get org-publish-html to delete the corresponding file in the html directory also?
If I have pages within subdirectories, how can I specify a single .css file in the root directory to be used for the style sheet? For instance, my directory structure is as follows:
public_html/
css/
mystyle.css
index.html
subdir/
index.html
With the following specifications in org-publish-project-alist (this is just a subset) --
:publishing-directory "public_html"
:style "<link rel=\"stylesheet\" href=\"css/mystyle.css\" type=\"text/css\"/>"
mystyle.css is used by public_html/index.html but not by public_html/subdir/index.html. Is there a simple remedy to this (I want the style sheet to be used by both/all files in subdirectories)?
Thanks much ~
There is no straightforward way of doing this. Org-mode doesn't know (or care) about the location to which it is publishing - it just sends things there and makes sure the correct directory structure exists. There is a hook in the publishing process that gets called after the files have been pushed to their published location. This is controlled by setting the :completion-function property in your org-publish-project-alist. You could use this hook to write a function that compares the *.org files in your base-dir and subdirectories to the accompanying *.html published files, and remove those *.html files that don't have an accompanying *.org file.
I suspect this will be most easily accomplished by making your Lisp completion-function call a shell script that removes the necessary files. If you are doing something fancy with the :include, :exclude, or :base-extension properties, you'll likely want your completion-function to grab the pertinent information from the plist and then pass them to your shell script. This org-mode page has an example completion-function that shows how to get property values for the org-publish-project-alist. You would then need to pass them to your shell script.
There are several ways to do this. Perhaps the simplest is to just override the default style sheet in each file with a line such as:
#+STYLE: <link rel="stylesheet" type="text/css" href="../stylesheet.css" />
for your first level of subdirectory files, and keep adding ../ as you get deeper in the directory structure.
Another possibility is generate generic template files for each level within the directory tree. This org-mode page gives a nice example of how to set this up.
Lastly, another option is to use the :preparation-function property of org-publish-project-alist to define a function that will automatically change the style file for each file. Again, this is probably best done by having the Lisp preparation-function call a shell script to parse the files. I could imagine doing this with the Unix sed program to find a regular expression denoted something like href="#MYLOC#/stylesheet.css" /> and substitute the stuff between #'s with the appropriate level within the directory tree. This seems like overkill, given the other options.