site: new system for generating versioned docs
This commit is contained in:
		
							parent
							
								
									dd86596d30
								
							
						
					
					
						commit
						99f52f719a
					
				
							
								
								
									
										58
									
								
								Shake.hs
									
									
									
									
									
								
							
							
						
						
									
										58
									
								
								Shake.hs
									
									
									
									
									
								
							| @ -53,14 +53,15 @@ usage = unlines | |||||||
|   ["Usage:" |   ["Usage:" | ||||||
|   ,"./Shake.hs               # compile this script" |   ,"./Shake.hs               # compile this script" | ||||||
|   ,"./Shake                  # show commands" |   ,"./Shake                  # show commands" | ||||||
|  |   ,"./Shake docs             # generate built-in manuals (plaintext, man, info)" | ||||||
|  |   ,"./Shake website          # generate the web site (web manuals, web pages)" | ||||||
|  | --   ,"./Shake manpages         # generate nroff files for man" | ||||||
|  | --   ,"./Shake txtmanpages      # generate text man pages for embedding" | ||||||
|  | --   ,"./Shake infomanpages     # generate info files for info" | ||||||
|  | --   ,"./Shake webmanpages      # generate individual web man pages for hakyll" | ||||||
|  | --   ,"./Shake webmanall        # generate all-in-one web manual for hakyll" | ||||||
|  |   ,"./Shake site/doc/VER/.snapshot   # generate and save a versioned web site snapshot" | ||||||
|   ,"./Shake all              # generate everything" |   ,"./Shake all              # generate everything" | ||||||
|   ,"./Shake docs             # generate general docs" |  | ||||||
|   ,"./Shake website          # generate the web site" |  | ||||||
|   ,"./Shake manpages         # generate nroff files for man" |  | ||||||
|   ,"./Shake txtmanpages      # generate text man pages for embedding" |  | ||||||
|   ,"./Shake infomanpages     # generate info files for info" |  | ||||||
|   ,"./Shake webmanpages      # generate web man pages for hakyll" |  | ||||||
|   ,"./Shake webmanual        # generate combined web man page for hakyll" |  | ||||||
|   ,"./Shake clean            # clean generated files" |   ,"./Shake clean            # clean generated files" | ||||||
|   ,"./Shake Clean            # clean harder" |   ,"./Shake Clean            # clean harder" | ||||||
|   ,"./Shake --help           # show options, eg --color" |   ,"./Shake --help           # show options, eg --color" | ||||||
| @ -93,8 +94,7 @@ main = do | |||||||
| -- | -- | ||||||
| --     "Shake" %> \out -> do | --     "Shake" %> \out -> do | ||||||
| --       need [out <.> "hs"] | --       need [out <.> "hs"] | ||||||
| --       unit $ cmd "./Shake.hs --version"  -- install libs via shebang line | --       unit $ cmd "./Shake.hs"  -- running as stack script installs deps and compiles | ||||||
| --       unit $ cmd "stack ghc Shake.hs" |  | ||||||
| --       putLoud "You can now run ./Shake instead of ./Shake.hs" | --       putLoud "You can now run ./Shake instead of ./Shake.hs" | ||||||
| 
 | 
 | ||||||
|     phony "all" $ need ["docs", "website"] |     phony "all" $ need ["docs", "website"] | ||||||
| @ -123,7 +123,7 @@ main = do | |||||||
|       --   manuals rendered to markdown, ready for web output by hakyll (site/hledger.md) |       --   manuals rendered to markdown, ready for web output by hakyll (site/hledger.md) | ||||||
|       webmanpages = ["site" </> manpageNameToUri m <.>"md" | m <- manpageNames] |       webmanpages = ["site" </> manpageNameToUri m <.>"md" | m <- manpageNames] | ||||||
|       --    manuals rendered to markdown and combined, ready for web output by hakyll |       --    manuals rendered to markdown and combined, ready for web output by hakyll | ||||||
|       webmanual = "site/manual.md" |       webmanall = "site/manual.md" | ||||||
| 
 | 
 | ||||||
|       -- hledger.1 -> hledger/doc, hledger_journal.5 -> hledger-lib/doc |       -- hledger.1 -> hledger/doc, hledger_journal.5 -> hledger-lib/doc | ||||||
|       manpageDir m |       manpageDir m | ||||||
| @ -208,11 +208,12 @@ main = do | |||||||
|     phony "website" $ do |     phony "website" $ do | ||||||
|       need $ |       need $ | ||||||
|         webmanpages ++ |         webmanpages ++ | ||||||
|         [webmanual |         [webmanall | ||||||
|         ,"releasemanual" |  | ||||||
|         ,hakyllstd |         ,hakyllstd | ||||||
|         ] |         ] | ||||||
|       cmd Shell (Cwd "site") "hakyll-std/hakyll-std" "build" |       cmd Shell (Cwd "site") "hakyll-std/hakyll-std" "build" | ||||||
|  |     -- website also links to old manuals, which are generated manually | ||||||
|  |     -- with ./Shake websnapshot and committed | ||||||
| 
 | 
 | ||||||
|     -- use m4 and pandoc to process macros and filter content, leaving markdown suitable for web output |     -- use m4 and pandoc to process macros and filter content, leaving markdown suitable for web output | ||||||
|     phony "webmanpages" $ need webmanpages |     phony "webmanpages" $ need webmanpages | ||||||
| @ -239,29 +240,30 @@ main = do | |||||||
|         ">>" out |         ">>" out | ||||||
| 
 | 
 | ||||||
|     -- adjust and combine man page mds for single-page web output, using pandoc |     -- adjust and combine man page mds for single-page web output, using pandoc | ||||||
|     phony "webmanual" $ need [ webmanual ] |     phony "webmanall" $ need [ webmanall ] | ||||||
| 
 | 
 | ||||||
|     webmanual %> \out -> do |     webmanall %> \out -> do | ||||||
|       need webmanpages |       need webmanpages | ||||||
|       liftIO $ writeFile webmanual "* toc\n\n" |       liftIO $ writeFile webmanall "* toc\n\n" | ||||||
|       forM_ webmanpages $ \f -> do -- site/hledger.md, site/journal.md |       forM_ webmanpages $ \f -> do -- site/hledger.md, site/journal.md | ||||||
|         cmd Shell ("printf '\\n\\n' >>") webmanual :: Action ExitCode |         cmd Shell ("printf '\\n\\n' >>") webmanall :: Action ExitCode | ||||||
|         cmd Shell "pandoc" f "-t markdown --atx-headers" |         cmd Shell "pandoc" f "-t markdown --atx-headers" | ||||||
|           -- "--filter doc/pandoc-drop-man-blocks" |           -- "--filter doc/pandoc-drop-man-blocks" | ||||||
|           "--filter doc/pandoc-drop-toc" |           "--filter doc/pandoc-drop-toc" | ||||||
|           -- "--filter doc/pandoc-capitalize-headers" |           -- "--filter doc/pandoc-capitalize-headers" | ||||||
|           "--filter doc/pandoc-demote-headers" |           "--filter doc/pandoc-demote-headers" | ||||||
|           ">>" webmanual :: Action ExitCode |           ">>" webmanall :: Action ExitCode | ||||||
| 
 |  | ||||||
|     -- check out and render manual pages for the current release also |  | ||||||
|     phony "releasemanual" $ need [ "releasemanual0.27" ] |  | ||||||
| 
 |  | ||||||
|     phony "releasemanual0.27" $ do |  | ||||||
|       -- XXX under doc so hakyll-std will render it |  | ||||||
|       cmd "mkdir -p site/doc/0.27" :: Action ExitCode |  | ||||||
|       cmd Shell "git show 0.27:doc/manual.md >site/doc/0.27/manual.md" :: Action ExitCode |  | ||||||
|       cmd Shell "patch site/doc/0.27/manual.md doc/manual0.27.diff " |  | ||||||
| 
 | 
 | ||||||
|  |     -- build the currently checked out web docs and save as a named snapshot | ||||||
|  |     "site/doc/*/.snapshot" %> \out -> do | ||||||
|  |       need [ webmanall ] | ||||||
|  |       let snapshot = takeDirectory out | ||||||
|  |       cmd Shell "mkdir -p" snapshot :: Action ExitCode | ||||||
|  |       forM_ webmanpages $ \f -> do -- site/hledger.md, site/journal.md | ||||||
|  |         cmd Shell "cp" f (snapshot </> takeFileName f) :: Action ExitCode | ||||||
|  |       cmd Shell "cp" "site/manual.md" snapshot :: Action ExitCode | ||||||
|  |       cmd Shell "cp -r site/images" snapshot :: Action ExitCode | ||||||
|  |       cmd Shell "touch" out -- :: Action ExitCode | ||||||
| 
 | 
 | ||||||
|     -- build standard hakyll script used for site rendering |     -- build standard hakyll script used for site rendering | ||||||
|     hakyllstd %> \out -> do |     hakyllstd %> \out -> do | ||||||
| @ -281,7 +283,9 @@ main = do | |||||||
|     phony "clean" $ do |     phony "clean" $ do | ||||||
|       putNormal "Cleaning generated files" |       putNormal "Cleaning generated files" | ||||||
|       removeFilesAfter "." webmanpages |       removeFilesAfter "." webmanpages | ||||||
|       removeFilesAfter "." [webmanual] |       removeFilesAfter "." [webmanall] | ||||||
|  |       -- removeFilesAfter "." ["site/doc/[0-9]*"] | ||||||
|  |       cmd Shell "rm -rf site/doc/[0-9]*" | ||||||
| 
 | 
 | ||||||
|     phony "Clean" $ do |     phony "Clean" $ do | ||||||
|       need ["clean"] |       need ["clean"] | ||||||
|  | |||||||
							
								
								
									
										19
									
								
								doc/lib.m4
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								doc/lib.m4
									
									
									
									
									
								
							| @ -14,16 +14,19 @@ m4_dnl Links to dev and recent release versions of a manual. | |||||||
| m4_dnl $1 is the manual's web slug: hledger, hledger-ui, journal, csv etc. | m4_dnl $1 is the manual's web slug: hledger, hledger-ui, journal, csv etc. | ||||||
| m4_dnl The current version is hidden (or whatever) by highlightDocVersion in site.js. | m4_dnl The current version is hidden (or whatever) by highlightDocVersion in site.js. | ||||||
| m4_dnl | m4_dnl | ||||||
| m4_define({{_docversionlinks_}}, | m4_define({{_docversionlinks_}},m4_dnl | ||||||
| <div class="versions"> |  | ||||||
| This doc is for version **_version_**. | This doc is for version **_version_**. | ||||||
| Available versions: | <span class="docversions">m4_dnl | ||||||
| <a href="$1.html">_version_</a> | m4_dnl Too painful for static generation, insert from site.js instead | ||||||
| | <a href="doc/1.0/$1.html">1.0</a> | m4_dnl Available versions: | ||||||
| | <a href="doc/0.27/manual.html{{#}}$1">0.27</a> | m4_dnl <a href="/$1.html">dev</a> | ||||||
| </div>)m4_dnl | m4_dnl | <a href="/doc/1.1/$1.html">1.1</a> | ||||||
|  | m4_dnl | <a href="/doc/1.0/$1.html">1.0</a> | ||||||
|  | m4_dnl | <a href="/doc/0.27/manual.html#$1">0.27</a> | ||||||
|  | </span>)m4_dnl | ||||||
| m4_dnl | m4_dnl | ||||||
| m4_define({{_toc_}}, {{* toc}})m4_dnl | m4_define({{_toc_}},{{ | ||||||
|  | * toc}})m4_dnl | ||||||
| m4_dnl | m4_dnl | ||||||
| m4_dnl _table_({{ | m4_dnl _table_({{ | ||||||
| m4_dnl | cell1 | cell2 ... | m4_dnl | cell1 | cell2 ... | ||||||
|  | |||||||
| @ -1,11 +0,0 @@ | |||||||
| 4a4,5
 |  | ||||||
| > <a name="hledger" />
 |  | ||||||
| > 
 |  | ||||||
| 6a7,12
 |  | ||||||
| > <div class="versions">
 |  | ||||||
| > This doc is for version **0.27**.
 |  | ||||||
| > Available versions:
 |  | ||||||
| > <a href="/manual.html">1.0</a>
 |  | ||||||
| > | <a href="doc/0.27/manual.html">0.27</a>
 |  | ||||||
| > </div>
 |  | ||||||
| > 
 |  | ||||||
							
								
								
									
										1
									
								
								site/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								site/.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -13,3 +13,4 @@ timeclock.md | |||||||
| timedot.md | timedot.md | ||||||
| manual.md | manual.md | ||||||
| [0-9].* | [0-9].* | ||||||
|  | .snapshot | ||||||
| @ -2,4 +2,4 @@ Static bits of the hledger.org website. | |||||||
| 
 | 
 | ||||||
| In some cases these are rendered to _site/* by hakyll (via the | In some cases these are rendered to _site/* by hakyll (via the | ||||||
| hakyll-std script), in others they are served directly from the git | hakyll-std script), in others they are served directly from the git | ||||||
| working copy. | working copy. (?) | ||||||
|  | |||||||
							
								
								
									
										5
									
								
								site/doc/README
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								site/doc/README
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,5 @@ | |||||||
|  | Snapshots of past versions of the web content. | ||||||
|  | These are in the "doc/" subdirectory so that hakyll-std will see them. | ||||||
|  | At each release, a new snapshot should be generated and committed. | ||||||
|  | Major releases should also be added to the "available | ||||||
|  | versions" links in site.js. | ||||||
| @ -1,12 +1,28 @@ | |||||||
| $(document).ready( function() { | $(document).ready( function() { | ||||||
|   highlightDocVersion(); |   addDocVersions(); | ||||||
|  |   highlightCurrentDocVersion(); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| function highlightDocVersion() { | function addDocVersions() { | ||||||
|   $('.versions').each( function() { |   var parts = window.location.pathname.split('/'); | ||||||
|  |   var page = parts.length > 0 ? parts[parts.length-1].slice(0,-5) : ''; | ||||||
|  |   var hash = window.location.hash.slice(1); | ||||||
|  |   var topic = (page=='manual' && hash) ? hash : page; | ||||||
|  |   var newhash = (page=='manual' && topic!='manual') ? ('#'+topic) : ''; | ||||||
|  |   var newpage = page=='manual' ? page : topic; | ||||||
|  |   $('.docversions').html('Available versions: \ | ||||||
|  | <a href="/'+newpage+'.html'+(page=='manual' ? newhash : '')+'">dev</a> \ | ||||||
|  | | <a href="/doc/1.1/'+newpage+'.html'+(page=='manual' ? newhash : '')+'">1.1</a> \ | ||||||
|  | | <a href="/doc/1.0/'+newpage+'.html'+(page=='manual' ? newhash : '')+'">1.0</a> \ | ||||||
|  | | <a href="/doc/0.27/manual.html'+(topic=='manual' ? '' : ('#'+topic))+'">0.27</a> \ | ||||||
|  | '); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function highlightCurrentDocVersion() { | ||||||
|  |   $('.docversions').each( function() { | ||||||
|     var parts = window.location.pathname.split('/'); |     var parts = window.location.pathname.split('/'); | ||||||
|     var dir = parts.length > 1 ? parts[parts.length-2] : ''; |     var dir = parts.length > 1 ? parts[parts.length-2] : ''; | ||||||
|     var ver = $.isNumeric(dir) ? dir : '1.1'; |     var ver = $.isNumeric(dir) ? dir : 'dev'; | ||||||
|     $(this).find('a').each( function() { |     $(this).find('a').each( function() { | ||||||
|       if ($(this).html() == ver) |       if ($(this).html() == ver) | ||||||
|         $(this) |         $(this) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user