aboutsummaryrefslogblamecommitdiffstats
path: root/readme.html
blob: b9c6574a39d95fe4bb14af7e286b07177143b5e3 (plain) (tree)
1
2

                                                            


















                                                                                                  

                                           
 





                                                                
 








                                                                                
 






                                                                                               
 




                                                                                                        
 











                                                                                                                               
 
                                                                                         
 






                                                                                                                                                                                                                                                                     
 


                                                                                                                                   
 


                                                                                                                                                                                


                                                           
                                                                                                








                                                                                                                         



                                                                                                                                                     
 
                                                                             



















                                                      

                                                                                                                                           


                                                   
                                                                         


















                                                                            

                                                                                                                                                             





                                                                              
                                                                                                                                                      
 


                                                                                                                                                               




                                                     
                                                         
















                                                           

                                                                                                                                                 
 
                                                                                              


































                                                                          
                                        










                                  
                                                           

































                                               

                                                                                                                                 





















                                                                                                                                                                        

                                                                   
             

                                                                                                                                         
 
                                                                                                                              










































                                                                             

                                                                                                                               






                                                                                                    

                                                                                                                               






                                                    

                                                                                                                                     






                                                                                            

                                                                                                                             






                                                                             



                                                                                                                                                                                       












































                                                                


                                                                                                                                                                                                                                                




                                                                                                                            


                                                                                       
                      







                                                                                                                                                                         

                                                                                                              

                                                                                                                                                   





                                                                                                                                                                                  

                                                                                                                               


                                                                    
                                                                                        















                                                                                                                                            

                                                                                                                                                                 


                                                                     
                                                                                                

    
                                                              




                                                                                          

                                                                                                                                                                                             

                        

                                                                                                                                                                                   

                             

                                                                                                                               




                                  

                                                                                                                                       
 

                                                                                                                                                  
<html><head><meta charset="utf-8"></head><body><article><pre
                     style="font-family: menlo, monotype;">
                     ██                 
                     ██          ██     
                     ██          ██     
  ▒█████░  ██░████   ██  ▓██▒  ███████  
 ████████  ███████▓  ██ ▓██▒   ███████  
 ██▒  ░▒█  ███  ▒██  ██▒██▒      ██     
 █████▓░   ██    ██  ████▓       ██     
 ░██████▒  ██    ██  █████       ██     
    ░▒▓██  ██    ██  ██░███      ██     
 █▒░  ▒██  ██    ██  ██  ██▒     ██░    
 ████████  ██    ██  ██  ▒██     █████  
 ░▓████▓   ██    ██  ██   ███    ░████  
                                        

              v.01 manual
               2/18/2018

</pre>

<ul>
<li><a href="#snkt" rel="nofollow">snkt</a>

<ul>
<li><a href="#why" rel="nofollow">Why</a></li>
<li><a href="#status" rel="nofollow">Status</a></li>
</ul></li>
<li><a href="#installation" rel="nofollow">Installation</a></li>
<li><a href="#quick-start" rel="nofollow">Quick Start</a>

<ul>
<li><a href="#creating-a-site" rel="nofollow">Creating a Site</a></li>
<li><a href="#first-post" rel="nofollow">First Post</a></li>
<li><a href="#viewing-the-results" rel="nofollow">Viewing the Results</a></li>
</ul></li>
<li><a href="#command-line-options" rel="nofollow">Command Line Options</a></li>
<li><a href="#configuration" rel="nofollow">Configuration</a></li>
<li><a href="#posts" rel="nofollow">Posts</a></li>
<li><a href="#templates" rel="nofollow">Templates</a>

<ul>
<li><a href="#home" rel="nofollow">home</a></li>
<li><a href="#post" rel="nofollow">post</a></li>
<li><a href="#archive" rel="nofollow">archive</a></li>
<li><a href="#rss" rel="nofollow">rss</a></li>
</ul></li>
<li><a href="#advanced-configuration-options" rel="nofollow">Advanced Configuration Options</a>

<ul>
<li><a href="#permalink-and-filename-formatter" rel="nofollow">Permalink and filename formatter</a></li>
<li><a href="#filters" rel="nofollow">Filters</a></li>
</ul></li>
<li><a href="#work-in-progress-features" rel="nofollow">Work in Progress Features</a>

<ul>
<li><a href="#paged-archives" rel="nofollow">Paged Archives</a></li>
<li><a href="#tags" rel="nofollow">Tags</a></li>
<li><a href="#binary-files-as-posts" rel="nofollow">Binary Files as Posts</a></li>
</ul></li>
<li><a href="#example-configurations-sites-themes" rel="nofollow">Example configurations, sites, themes</a></li>
<li><a href="#rebuild-and-deployment-recipes" rel="nofollow">Rebuild and deployment recipes</a></li>
<li><a href="#todo" rel="nofollow">TODO</a></li>
<li><a href="#feedback" rel="nofollow">Feedback</a></li>
</ul>
<h1><a name="snkt" class="anchor" href="#snkt" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
snkt</h1>

<p><code>snkt</code> is a static site generator focused on simplicity and efficiency.</p>

<p><code>snkt</code> does a few things, but strives to do them coherently.</p>

<p><code>snkt</code> generates my <a href="https://trenchant.org/daily/2017/1/31/" rel="nofollow">personal web site of ~2000 articles in under a second</a>. It should be fast enough to completely regenerate even very large sites in near real-time if needed.</p>
<h2><a name="why" class="anchor" href="#why" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
Why</h2>

<p>Every 5-10 years I throw out the software for my site and rewrite it.</p>

<p>This time it&#39;s in Go. Maybe you&#39;ll find it useful. It&#39;s 10x faster than the old version in Python.</p>
<h2><a name="status" class="anchor" href="#status" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
Status</h2>

<p>It powers <a href="https://trenchant.org" rel="nofollow">trenchant.org</a> but is under active development and pieces may change. See TODO for future / in progress work.</p>
<h1><a name="installation" class="anchor" href="#installation" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
Installation</h1>

<p>The only dependency for building is <code>go</code>.</p>

<p><a href="https://golang.org/doc/install" rel="nofollow">Install Go</a> for your platform.</p>

<p>Download and build <code>snkt</code> with something like</p>

<pre><code>$ go get adammathes.com/snkt
</code></pre>

<p>This will download dependencies, build <code>snkt</code> and place it in your $GOPATH/bin (by default, ~/go/bin/).</p>

<p><code>snkt</code> is a self-contained binary, you can move it anywhere.</p>
<h1><a name="quick-start" class="anchor" href="#quick-start" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
Quick Start</h1>
<h2><a name="creating-a-site" class="anchor" href="#creating-a-site" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
Creating a Site</h2>

<p>Use the &#34;-init&#34; option to create the skeleton for a new site -</p>

<pre><code>$ snkt -i myblog
</code></pre>

<p>This will create:</p>

<ul>
<li><code>txt</code> directory for posts</li>
<li><code>html</code> directory for HTML output</li>
<li><code>tmpl</code> directory for templates

<ul>
<li><code>base</code> HTML structure wrapper</li>
<li><code>archive</code> lists all posts</li>
<li><code>post</code> single post page</li>
<li><code>home</code> home page with recent posts</li>
<li><code>rss</code> RSS 2.0</li>
</ul></li>
<li><code>config.yml</code> configuration file</li>
</ul>
<h2><a name="first-post" class="anchor" href="#first-post" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
First Post</h2>

<p>A one line plaint text file is a valid post.</p>

<pre><code>user@host:~/myblog$ echo &#34;hello world&#34; &gt;&gt; txt/hi
</code></pre>

<p>Build the site</p>

<pre><code>$ snkt -b
</code></pre>

<p>Output should now be in the <code>html</code> directory and look like</p>

<ul>
<li><code>html</code>

<ul>
<li><code>hi/index.html</code> hello world post</li>
<li><code>index.html</code></li>
<li><code>archive.html</code></li>
<li><code>rss.xml</code></li>
</ul></li>
</ul>
<h2><a name="viewing-the-results" class="anchor" href="#viewing-the-results" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
Viewing the Results</h2>

<p><code>snkt</code> includes a simple web server to view the results with</p>

<pre><code>$ snkt -p
</code></pre>

<p>Visiting <a href="http://localhost:8000" rel="nofollow">http://localhost:8000</a> in a web browser should now show the site and the first post.</p>

<p>You can now copy this HTML anywhere and you&#39;re set.</p>
<h1><a name="command-line-options" class="anchor" href="#command-line-options" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
Command Line Options</h1>

<pre><code>Usage of snkt:
  -b, --build
    	generates site from input files and templates
  -c, --config configuration
    	configuration file (default &#34;config.yml&#34;)
  -h, --help
    	print usage information
  -i, --init directory
    	initialize new site at directory
  -s, --serve
    	serve site via integrated HTTP server
  -v, --verbose
    	log operations during build to STDOUT
  -w, --watch
    	watch configured input text dir, rebuild on changes
</code></pre>

<p>Examples</p>

<pre><code>$ snkt -c site.yaml -b
$ snkt --config=myconfig.yml -v -w
</code></pre>
<h1><a name="configuration" class="anchor" href="#configuration" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
Configuration</h1>

<p>Per site configuration is via a <a href="http://yaml.org" rel="nofollow">YAML</a> file.</p>

<p>For most purposes, it should just be a listing of attribute : value</p>

<p>Configuration options --</p>

<table>
<thead>
<tr>
<th>name</th>
<th>value</th>
<th>default</th>
</tr>
</thead>

<tbody>
<tr>
<td><code>input_dir</code></td>
<td>absolute path of directory for text input files</td>
<td></td>
</tr>

<tr>
<td><code>output_dir</code></td>
<td>absolute path of directory for html output files</td>
<td></td>
</tr>

<tr>
<td><code>tmpl_dir</code></td>
<td>absolute path of directory for template files</td>
<td></td>
</tr>

<tr>
<td><code>site_title</code></td>
<td>string for the site&#39;s title</td>
<td></td>
</tr>

<tr>
<td><code>site_url</code></td>
<td>absolute URL for the site</td>
<td></td>
</tr>

<tr>
<td><code>filters</code></td>
<td>list of search/replace regex&#39;s to run on posts</td>
<td></td>
</tr>

<tr>
<td><code>permalink_fmt</code></td>
<td>format string for permalinks</td>
<td>/%F/</td>
</tr>

<tr>
<td><code>post_file_fmt</code></td>
<td>format string for post filenames</td>
<td>/%F/index.html</td>
</tr>

<tr>
<td><code>show_future</code></td>
<td>include posts with dates in the future</td>
<td>false</td>
</tr>

<tr>
<td><code>preview_server</code></td>
<td>host:port to spawn the preview server</td>
<td>localhost:8000</td>
</tr>

<tr>
<td><code>preview_dir</code></td>
<td>root directory of preview server</td>
<td><code>output_dir</code></td>
</tr>
</tbody>
</table>
<h1><a name="posts" class="anchor" href="#posts" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
Posts</h1>

<p>Post inputs are stored as plain text files. (I have only tested UTF-8 and ASCII.)</p>

<p>Posts have an optional metadata preamble, and a markdown formatted body. The preamble is just a series of name value pairings separated by a colon (:) character.</p>

<p>Minimal complete and valid post --</p>

<pre><code>this is a totally valid post
</code></pre>

<p>Post with a preamble --</p>

<pre><code>title: also a valid post
date: 2017-02-08
valid: totes

This post will have an explicitly set title (ooh! fancy!) 
instead of inferred from the filename. 

It will also have an explicitly set date instead of inferring 
it from the file creation/modification time.

`totes` will be stored in the post&#39;s `meta` map under `valid.` 
You don&#39;t have to worry about that right now. Honest.
</code></pre>
<h1><a name="templates" class="anchor" href="#templates" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
Templates</h1>

<p>Templates use the standard library <a href="https://golang.org/pkg/text/template/" rel="nofollow">Go text/template</a>.</p>

<p>Entities in the templates --</p>

<p><strong>Site</strong></p>

<pre><code>	Title string
	URL   string
	Posts array of posts
</code></pre>

<p>See site/site.go for more.</p>

<p><strong>Post</strong></p>

<pre><code>	// Metadata
	Meta       map[string]string
	SourceFile string
	Title      string 
	Permalink  string
	Time       time.Time
	Year       int
	Month      time.Month
	Day        int
	InFuture   bool

	// Content text -- raw, unprocessed, unfiltered markdown
	Text string

	// Content text -- processed into HTML via markdown and other filters
	Content string

	// Content with sources and references resolved to absolute URLs
	AbsoluteContent string

	// Post following chronologically (later)
	Next *Post
	// Post preceding chronologically (earlier)
	Prev *Post

	// Precomputed dates as strings
	Date    string
	RssDate string
</code></pre>
<h2><a name="home" class="anchor" href="#home" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
home</h2>

<p>Displays recent posts and rendered to <code>index.html</code> in the <code>output_dir</code>.</p>

<ul>
<li>{{.Site}} <em>Site</em></li>
<li>{{.Posts}} <em>Posts</em> all posts on site in reverse chronological order</li>
</ul>
<h2><a name="post" class="anchor" href="#post" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
post</h2>

<p>Each individual post uses this template</p>

<ul>
<li>{{.Site}} <em>Site</em></li>
<li>{{.Post}} <em>Post</em> the individual post</li>
</ul>
<h2><a name="archive" class="anchor" href="#archive" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
archive</h2>

<p>Lists all posts, showing only titles and links. Rendered to <code>archive.html</code></p>

<ul>
<li>{{.Site}} <em>Site</em></li>
<li>{{.Posts}} <em>Posts</em> all posts, reverse chronological order</li>
</ul>
<h2><a name="rss" class="anchor" href="#rss" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
rss</h2>

<p>Displays recent posts as RSS 2.0 XML. Rendered to <code>rss.xml</code></p>

<ul>
<li>{{.Site}} <em>Site</em></li>
<li>{{.Posts}} <em>Posts</em> all posts, reverse chronological order</li>
</ul>
<h1><a name="advanced-configuration-options" class="anchor" href="#advanced-configuration-options" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
Advanced Configuration Options</h1>
<h2><a name="permalink-and-filename-formatter" class="anchor" href="#permalink-and-filename-formatter" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
Permalink and filename formatter</h2>

<p>Permalinks (URLs for individual posts) can be customized.</p>

<table>
<thead>
<tr>
<th>String</th>
<th>Value</th>
<th>Example</th>
</tr>
</thead>

<tbody>
<tr>
<td>%Y</td>
<td>Year</td>
<td>2017</td>
</tr>

<tr>
<td>%M</td>
<td>Month</td>
<td>04</td>
</tr>

<tr>
<td>%D</td>
<td>Day</td>
<td>14</td>
</tr>

<tr>
<td>%F</td>
<td>Filename</td>
<td>foo</td>
</tr>

<tr>
<td>%T</td>
<td>Title</td>
<td>bar</td>
</tr>
</tbody>
</table>

<p><code>Filename</code> is a cleaned version of the post&#39;s original filename with the extension removed. Filenames and titles will be &#34;cleaned&#34; of characters unsuitable for links, with whitespace replaced by <code>-</code>.</p>
<h2><a name="filters" class="anchor" href="#filters" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
Filters</h2>

<p>Arbitrary regular expressions can be executed on each post to create domain-specific and site-specific modifications.</p>

<p>Here are the real world examples of regular expressions that filter each post on my personal site -</p>

<div class="highlight highlight-yaml"><pre>filters:
  - s: &lt;photo id=&#34;(.+)&#34;&gt;
    r: &lt;div class=&#34;photo&#34;&gt;&lt;img src=&#34;/img/$1&#34; /&gt;&lt;/div&gt;
  - s: &lt;segue /&gt;
    r: &lt;p class=&#34;segue&#34;&gt;&amp;middot; &amp;middot; &amp;middot;&lt;/p&gt;
  - s: &lt;youtube id=&#34;(.+)&#34;&gt;
    r: &lt;p class=&#34;video&#34;&gt;&lt;a href=&#34;https://www.youtube.com/watch?v=$1&#34;&gt;&lt;img src=&#34;/img/$1.jpg&#34; /&gt;&lt;/a&gt;&lt;/p&gt;
  - s: &#34;amazon:(.+)&#34;
    r: &#34;http://www.amazon.com/exec/obidos/ASIN/$1/decommodify-20/&#34;
</pre></div>
<h1><a name="work-in-progress-features" class="anchor" href="#work-in-progress-features" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
Work in Progress Features</h1>

<p>These features are working but less documented and potentially still in progress and subject to change.</p>
<h2><a name="paged-archives" class="anchor" href="#paged-archives" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
Paged Archives</h2>

<p>If a template named <code>paged</code> is present then paged archives (15 posts per page) are created at <code>output_dir/page/%d.html</code></p>

<p>Template variables are the same as the <code>archive</code> template, but with <code>.NextPage</code> and <code>.PrevPage</code> as integers of the next and previous page.</p>

<p>See archive/paged.go for details.</p>
<h2><a name="tags" class="anchor" href="#tags" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
Tags</h2>

<p>There is preliminary support for tag style metadata per post.</p>

<p>Add a &#34;tags&#34; field to your post preamble. Tags should be comma separated.</p>

<pre><code>    tags: TagOne, tag two, a third tag, fourth

</code></pre>

<p>Tags will be normalized to lowercase, with spaces replaced with underscores. So the above would have tagged a post with --</p>

<p><code>tagone tag_two a_third_tag fourth</code></p>

<p>Tags are accessible in each post via the <code>Tags</code> field.</p>

<p>To create pages by tag, create a template named <code>tags</code>.</p>

<p>This creates a file at OUTPUT_DIR/tag/tag_name/index.html for each tag.</p>

<p>It will have access to the same variables as an <code>archive</code> template with the additional <code>.Tag</code> for the tag name.</p>
<h2><a name="binary-files-as-posts" class="anchor" href="#binary-files-as-posts" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
Binary Files as Posts</h2>

<p>Preliminary support to treat binary files as standalone posts.</p>

<p>Drop image files with &#34;jpg&#34; or other image extensions into the &#34;txt&#34; dir.</p>

<ul>
<li>post&#39;s ContentType will be set to &#34;image&#34;</li>
<li>text fields will be empty strings</li>
<li>metadata will be populated as it can via exif (maybe)</li>
</ul>

<p>Video and audio files have preliminary support too -- see <code>post/post.go</code></p>
<h1><a name="example-configurations-sites-themes" class="anchor" href="#example-configurations-sites-themes" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
Example configurations, sites, themes</h1>

<p><em>not done</em></p>
<h1><a name="rebuild-and-deployment-recipes" class="anchor" href="#rebuild-and-deployment-recipes" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
Rebuild and deployment recipes</h1>

<p><em>also not done</em></p>
<h1><a name="todo" class="anchor" href="#todo" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
TODO</h1>

<ul>
<li>sample sites/templates</li>
<li>proper man pages for docs</li>
</ul>
<h1><a name="feedback" class="anchor" href="#feedback" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>
Feedback</h1>

<p>Pull requests and issues are welcomed at <a href="https://github.com/adammathes/snkt" rel="nofollow">https://github.com/adammathes/snkt</a></p>
</article></body></html>