Posts mit dem Label html templates werden angezeigt. Alle Posts anzeigen
Posts mit dem Label html templates werden angezeigt. Alle Posts anzeigen

Dienstag, 5. August 2014

Automate html creation with the linux dash

Overview

This article describes the basic concepts for html generation with the linux dash command interpreter.


Example: Video Collection

The dash command line interpreter can be used to generate video player websites for each video in a directory.

Example: Video Collection
Example Video Collection


Dash commands


for - loop through files

Use the for-command to loop through every file. The example below loops through all mp4-files.
for filename in *.mp4;do echo $filename; done

The for-command can also be used to generate video thumbnails and background-images with a video formats converter.


while - loop through code lines

Use the while-command to loop through every line of a file. The example below will read the html template file template.html and loop trough all its lines and replace the SSI-variable *VARIABLE* by the dash variable $variable. In this example the output file is vidcenter.html.
while read line;do
    line=$(echo $line | sed "s/\*VARIABLE\*/$variable/")   
    echo $line >> "vidcenter.html"
done < "template.html"

Conclusion

'for' and 'while' are handy dash commands for linux to generate html from templates, replace variables and run video converters on the fly.