configurable tocs

This commit is contained in:
Mirek Kratochvil 2023-06-18 22:11:01 +02:00
parent 8fd47d38bb
commit 6cd0b9f663
10 changed files with 59 additions and 24 deletions

View file

@ -25,3 +25,7 @@ htmlWriteOpts =
-- | Default plaintext writing options for Pandoc.
plainWriteOpts :: WriterOptions
plainWriteOpts = def {writerWrapText = WrapNone}
-- | Default options for making tables of contents with certain depth.
tocWriteOpts :: Int -> WriterOptions
tocWriteOpts n = def { writerTOCDepth = n}

View file

@ -62,3 +62,6 @@ hasUriScheme x = all id . zipWith (==) x . (++ ":")
unAbsolute :: String -> String
unAbsolute = dropWhile (== '/')
withPandocBlocks :: ([Block] -> [Block]) -> Pandoc -> Pandoc
withPandocBlocks f (Pandoc meta blocks) = Pandoc meta (f blocks)

View file

@ -122,7 +122,7 @@ blockquote {
}
.sidebox ul {
padding-left: 0em;
padding-left: 1em;
list-style-type: none;
margin: 0;
margin-bottom: 0.5em;
@ -132,11 +132,18 @@ blockquote {
text-align: right;
}
li.sidebox-tag {
padding-left: 1em;
text-indent: -1em;
}
.sidebox-toc a {
display: inline-block;
padding-left: 1em;
text-indent: -1em;
}
/* search form and related stuff */
.search-form-wrap {
@ -370,7 +377,6 @@ main {
}
.sidebox-values {
padding-left: 1em;
margin-bottom: 1em;
font-size: 80%;
}

View file

@ -14,6 +14,7 @@ redirects:
tags:
- publication/ppc/code
- it/license
toc: 2
---
# How-to: Pass a PPC code check

View file

@ -2,6 +2,7 @@
mount: /
title: Home
template: index.html
toc: off
---
#### What are How-To Cards?

View file

@ -5,22 +5,13 @@ tags:
title: How-To Cards data license
---
# Creative Commons Attribution-ShareAlike 4.0 International
The contents of How-To Cards are licensed under CC-BY-SA 4.0 license. The full text of the license follows:
Creative Commons Corporation (“Creative Commons”) is not a law firm and does not provide legal services or legal advice. Distribution of Creative Commons public licenses does not create a lawyer-client or other relationship. Creative Commons makes its licenses and related information available on an “as-is” basis. Creative Commons gives no warranties regarding its licenses, any material licensed under their terms and conditions, or any related information. Creative Commons disclaims all liability for damages resulting from their use to the fullest extent possible.
### Using Creative Commons Public Licenses
Creative Commons public licenses provide a standard set of terms and conditions that creators and other rights holders may use to share original works of authorship and other material subject to copyright and certain other rights specified in the public license below. The following considerations are for informational purposes only, are not exhaustive, and do not form part of our licenses.
* __Considerations for licensors:__ Our public licenses are intended for use by those authorized to give the public permission to use material in ways otherwise restricted by copyright and certain other rights. Our licenses are irrevocable. Licensors should read and understand the terms and conditions of the license they choose before applying it. Licensors should also secure all rights necessary before applying our licenses so that the public can reuse the material as expected. Licensors should clearly mark any material not subject to the license. This includes other CC-licensed material, or material used under an exception or limitation to copyright. [More considerations for licensors](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensors).
* __Considerations for the public:__ By using one of our public licenses, a licensor grants the public permission to use the licensed material under specified terms and conditions. If the licensors permission is not necessary for any reasonfor example, because of any applicable exception or limitation to copyrightthen that use is not regulated by the license. Our licenses grant only permissions under copyright and certain other rights that a licensor has authority to grant. Use of the licensed material may still be restricted for other reasons, including because others have copyright or other rights in the material. A licensor may make special requests, such as asking that all changes be marked or described. Although not required by our licenses, you are encouraged to respect those requests where reasonable. [More considerations for the public](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensees).
## Creative Commons Attribution-ShareAlike 4.0 International Public License
# Creative Commons Attribution-ShareAlike 4.0 International Public License
By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions.
### Section 1 Definitions.
## Section 1 Definitions.
a. __Adapted Material__ means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image.
b. __Adapter's License__ means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License.
@ -36,7 +27,7 @@ k. __Share__ means to provide material to the public by any means or process tha
l. __Sui Generis Database Rights__ means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world.
m. __You__ means the individual or entity exercising the Licensed Rights under this Public License. __Your__ has a corresponding meaning.
### Section 2 Scope.
## Section 2 Scope.
a. ___License grant.___
1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to:
@ -55,7 +46,7 @@ b. ___Other rights.___
2. Patent and trademark rights are not licensed under this Public License.
3. To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties.
### Section 3 License Conditions.
## Section 3 License Conditions.
Your exercise of the Licensed Rights is expressly made subject to the following conditions.
@ -78,7 +69,7 @@ b. ___ShareAlike.___
2. You must include the text of, or the URI or hyperlink to, the Adapter's License You apply. You may satisfy this condition in any reasonable manner based on the medium, means, and context in which You Share Adapted Material.
3. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, Adapted Material that restrict exercise of the rights granted under the Adapter's License You apply.
### Section 4 Sui Generis Database Rights.
## Section 4 Sui Generis Database Rights.
Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material:
@ -88,13 +79,13 @@ c. You must comply with the conditions in Section 3(a) if You Share all or a sub
For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights.
### Section 5 Disclaimer of Warranties and Limitation of Liability.
## Section 5 Disclaimer of Warranties and Limitation of Liability.
a. __Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.__
b. __To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You.__
c. The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability.
### Section 6 Term and Termination.
## Section 6 Term and Termination.
a. This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically.
b. Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates:
@ -105,12 +96,12 @@ b. Where Your right to use the Licensed Material has terminated under Section 6(
c. For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License.
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public License.
### Section 7 Other Terms and Conditions.
## Section 7 Other Terms and Conditions.
a. The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed.
b. Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License.
### Section 8 Interpretation.
## Section 8 Interpretation.
a. For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License.
b. To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions.

View file

@ -3,6 +3,7 @@ mount: /search
title: Search
template: search.html
search: off
toc: off
---
# Search

View file

@ -24,6 +24,7 @@ executable site
, pandoc-types
, parsec
, SHA
, scientific
, text
, transformers
, yaml

23
site.hs
View file

@ -3,7 +3,7 @@
-- | The main deployment script.
module Main where
import Control.Monad ((>=>), unless, when)
import Control.Monad ((>=>), unless, when, join)
import Control.Monad.Extra (whenM)
import Control.Monad.Trans.State.Lazy
import qualified Data.Aeson as AE
@ -15,6 +15,7 @@ import Data.Foldable (traverse_)
import Data.List (inits, nub, sort)
import Data.List.Extra (groupSort)
import qualified Data.Map as M
import qualified Data.Scientific
import qualified Data.Set as S
import Data.String (fromString)
import qualified Data.Text as T
@ -36,9 +37,11 @@ import System.FilePath
)
import qualified Text.Mustache as Mu
import Text.Pandoc.Class (runIOorExplode)
import qualified Text.Pandoc.Definition
import Text.Pandoc.Readers.Markdown (readMarkdown)
import Text.Pandoc.Writers (writePlain)
import Text.Pandoc.Writers.HTML (writeHtml5String)
import Text.Pandoc.Writers.Shared (toTableOfContents)
import qualified Text.Parsec.Error
import FormatOpts
@ -175,6 +178,22 @@ addPageMeta pi (Y.Object m) = do
to splitDirectories
pure . Y.Object $ KM.insert "htags" (Y.array htagMeta) m
-- | If viable for a page (by config), add the TOC field
addTOC :: PageInfo -> Text.Pandoc.Definition.Pandoc -> Y.Value -> Site Y.Value
addTOC pi doc meta@(Y.Object meta') =
let go n = do
toc <-
io . runIOorExplode $ writeHtml5String htmlWriteOpts $
withPandocBlocks
(pure . toTableOfContents (tocWriteOpts n))
doc
pure . Y.Object $ KM.insert "toc" (Y.String toc) meta'
in case ( pi ^? pageMeta . key "toc" . _Bool
, join $ pi ^? pageMeta . key "toc" . _Number . to Data.Scientific.toBoundedInteger) of
(Just False, _) -> pure meta
(_, Nothing) -> go (3 :: Int)
(_, Just n) -> go n
-- | Render a page using the current template.
installPage :: FilePath -> PageInfo -> Site ()
installPage mount pi = do
@ -189,7 +208,7 @@ installPage mount pi = do
addHeadingLinks "header-local-anchor" fixedUrlDoc
let Y.Object meta' = pi ^. pageMeta
meta = Y.Object $ KM.insert "body" (Y.String body) meta'
meta <- addGlobalMeta meta >>= addPageMeta pi
meta <- addGlobalMeta meta >>= addTOC pi fixedUrlDoc >>= addPageMeta pi
io $ do
putStrLn $ "P -> " ++ file
makeDirectories file

View file

@ -32,7 +32,7 @@
</div>
{{?htags}}
<div class="sidebox-header">
Page categories
Card categories
</div>
<div class="sidebox-values">
<ul>
@ -42,5 +42,13 @@
</ul>
</div>
{{/htags}}
{{?toc}}
<div class="sidebox-header">
Card outline
</div>
<div class="sidebox-values sidebox-toc">
{{{toc}}}
</div>
{{/toc}}
</div>
<div class="content width-content">