├── .gitignore
├── .gitmodules
├── README.md
├── assets
├── _custom.scss
└── _variables.scss
├── config
├── _default
│ └── config.toml
├── pdf
│ └── config.toml
└── website
│ └── config.toml
├── content
├── _index.md
├── all
│ └── _index.md
├── docs
│ ├── example
│ │ ├── _index.md
│ │ ├── collapsed
│ │ │ ├── 3rd-level
│ │ │ │ ├── 4th-level.md
│ │ │ │ └── _index.md
│ │ │ └── _index.md
│ │ ├── hidden.md
│ │ └── table-of-contents
│ │ │ ├── _index.md
│ │ │ ├── with-toc.md
│ │ │ └── without-toc.md
│ └── shortcodes
│ │ ├── _index.md
│ │ ├── buttons.md
│ │ ├── columns.md
│ │ ├── details.md
│ │ ├── expand.md
│ │ ├── hints.md
│ │ ├── katex.md
│ │ ├── mermaid.md
│ │ └── tabs.md
├── menu
│ └── index.md
└── posts
│ ├── _index.md
│ ├── creating-a-new-theme.md
│ ├── goisforlovers.md
│ ├── hugoisforlovers.md
│ └── migrate-from-jekyll.md
├── layouts-pdf
├── all
│ └── list.html
└── pageinpdf.html
├── layouts
└── partials
│ └── docs
│ └── menu.html
├── netlify.toml
├── package-lock.json
├── package.json
├── resources
└── _gen
│ └── assets
│ └── scss
│ ├── book.scss_50fc8c04e12a2f59027287995557ceff.content
│ ├── book.scss_50fc8c04e12a2f59027287995557ceff.json
│ └── example
│ ├── book.scss_50fc8c04e12a2f59027287995557ceff.content
│ └── book.scss_50fc8c04e12a2f59027287995557ceff.json
└── testbook.Rproj
/.gitignore:
--------------------------------------------------------------------------------
1 | .Rhistory
2 | .RData
3 | .Rproj.user
4 | public
5 | public2
6 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "themes/hugo-book"]
2 | path = themes/hugo-book
3 | url = https://github.com/alex-shpak/hugo-book.git
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # testbook
3 |
4 |
5 | [](https://app.netlify.com/sites/hugo-pagedjs-book/deploys)
6 | [](https://www.repostatus.org/#concept)
7 |
8 |
9 | The goal of testbook is to try and generate a beautiful book as html and PDF using [Hugo](https://gohugo.io/) and [paged.js](https://www.pagedjs.org/).
10 | It's a proof-of-concept.
11 |
12 | The .md files could be created from .Rmd, therefore making this an alternative to the excellent [`bookdown`](https://github.com/rstudio/bookdown).
13 | Compared to creating a gitbook with `bookdown`, one could customize the html website more easily, and use any Hugo feature.
14 |
15 | This proof-of-concept is based on the great [hugo-book theme](https://github.com/alex-shpak/hugo-book).
16 | This repo just adds a bit of setup magic (Netlify config, config/ dir) to work with existing great tools.
17 |
18 | The idea is to run two Hugo builds with [different configurations](https://gohugo.io/getting-started/configuration/)
19 |
20 | * One of them, `hugo -d public --environment 'website'`, creates the html website with a link to "book.pdf" somewhere, in the public/ folder.
21 | * The second one, `hugo -d public2 --environment 'pdf'`, creates a website with a special page containing _all_ the book content, and potentially a print CSS stylesheet.
22 | * Then that page is printed to PDF using pagedjs-cli and copied as "book.pdf" to public/. `pagedjs-cli public2/all/index.html -o public/book.pdf"`
23 | * The live website uses public so it has the website and the PDF.
24 |
25 | Netlify can run all these commands
26 |
27 | ```toml
28 | [build]
29 | publish = "/public"
30 | command = "hugo -d public --environment 'website' && hugo -d public2 --environment 'pdf' && pagedjs-cli public2/all/index.html -o public/book.pdf"
31 | ```
32 |
33 | The dependency on pagedjs-cli is indicated with packages.json.
34 |
35 | ## Further work
36 |
37 | If I decide to take this further, that is!
38 |
39 | * Actually work on the CSS print sheet.
40 | * Make Katex, Mermaid etc. work for the PDF version.
41 | * Make hugo-book features for ordering/including content work.
42 | * Try and embed a tweet.
43 | * Try the idea with another book theme?
44 | * Write some content from Rmd.
45 |
46 | ## Related work
47 |
48 | To get a paged.js button in your Hugo website (i.e. not pre-generating the PDF, letting the reader do that from their browser) check out the [Hugo paged-js theme](https://gitlab.pagedmedia.org/julientaq/pagedjs-hugo) that you could use as a [theme component](https://gohugo.io/hugo-modules/theme-components/).
49 |
--------------------------------------------------------------------------------
/assets/_custom.scss:
--------------------------------------------------------------------------------
1 | /* You can add custom styles here. */
2 |
3 | // @import "plugins/numbered";
4 | // @import "plugins/scrollbars";
5 |
--------------------------------------------------------------------------------
/assets/_variables.scss:
--------------------------------------------------------------------------------
1 | /* You can override SASS variables here. */
2 |
3 | // @import "plugins/dark";
4 |
--------------------------------------------------------------------------------
/config/_default/config.toml:
--------------------------------------------------------------------------------
1 | # hugo server --minify --themesDir ... --baseURL=http://0.0.0.0:1313/theme/hugo-book/
2 |
3 | baseURL = 'https://hugo-pagedjs-book.netlify.app/'
4 | title = 'Hugo Book'
5 | theme = 'hugo-book'
6 |
7 | # Book configuration
8 | disablePathToLower = true
9 | enableGitInfo = true
10 |
11 | # Needed for mermaid/katex shortcodes
12 | [markup]
13 | [markup.goldmark.renderer]
14 | unsafe = true
15 |
16 | [markup.tableOfContents]
17 | startLevel = 1
18 |
19 | # Multi-lingual mode config
20 | # There are different options to translate files
21 | # See https://gohugo.io/content-management/multilingual/#translation-by-filename
22 | # And https://gohugo.io/content-management/multilingual/#translation-by-content-directory
23 | [languages]
24 | [languages.en]
25 | languageName = 'English'
26 | contentDir = 'content'
27 | weight = 1
28 |
29 | [menu]
30 | # [[menu.before]]
31 | [[menu.after]]
32 | name = "Github"
33 | url = "https://github.com/alex-shpak/hugo-book"
34 | weight = 10
35 |
36 | [[menu.after]]
37 | name = "Hugo Themes"
38 | url = "https://themes.gohugo.io/hugo-book/"
39 | weight = 20
40 |
41 | [params]
42 | # (Optional, default true) Controls table of contents visibility on right side of pages.
43 | # Start and end levels can be controlled with markup.tableOfContents setting.
44 | # You can also specify this parameter per page in front matter.
45 | BookToC = true
46 |
47 | # (Optional, default none) Set the path to a logo for the book. If the logo is
48 | # /static/logo.png then the path would be logo.png
49 | # BookLogo = 'logo.png'
50 |
51 | # (Optional, default none) Set leaf bundle to render as side menu
52 | # When not specified file structure and weights will be used
53 | # BookMenuBundle = '/menu'
54 |
55 | # (Optional, default docs) Specify root page to render child pages as menu.
56 | # Page is resoled by .GetPage function: https://gohugo.io/functions/getpage/
57 | # For backward compatibility you can set '*' to render all sections to menu. Acts same as '/'
58 | BookSection = 'docs'
59 |
--------------------------------------------------------------------------------
/config/pdf/config.toml:
--------------------------------------------------------------------------------
1 | layoutDir = 'layouts-pdf'
--------------------------------------------------------------------------------
/config/website/config.toml:
--------------------------------------------------------------------------------
1 | layoutDir = 'layouts'
2 |
3 | # Set source repository location.
4 | # Used for 'Last Modified' and 'Edit this page' links.
5 | BookRepo = 'https://github.com/alex-shpak/hugo-book'
6 |
7 | # Enable "Edit this page" links for 'doc' page type.
8 | # Disabled by default. Uncomment to enable. Requires 'BookRepo' param.
9 | # Edit path must point to root directory of repo.
10 | BookEditPath = 'edit/master/'
11 |
12 | # Configure the date format used on the pages
13 | # - In git information
14 | # - In blog posts
15 | BookDateFormat = 'January 2, 2006'
16 |
17 | # (Optional, default true) Enables search function with flexsearch,
18 | # Index is built on fly, therefore it might slowdown your website.
19 | # Configuration for indexing can be adjusted in i18n folder per language.
20 | BookSearch = true
21 |
22 | # (Optional, default true) Enables comments template on pages
23 | # By default partals/docs/comments.html includes Disqus template
24 | # See https://gohugo.io/content-management/comments/#configure-disqus
25 | # Can be overwritten by same param in page frontmatter
26 | BookComments = true
27 |
28 | # /!\ This is an experimental feature, might be removed or changed at any time
29 | # (Optional, experimental, default false) Enables portable links and link checks in markdown pages.
30 | # Portable links meant to work with text editors and let you write markdown without {{< relref >}} shortcode
31 | # Theme will print warning if page referenced in markdown does not exists.
32 | BookPortableLinks = true
33 |
34 | # /!\ This is an experimental feature, might be removed or changed at any time
35 | # (Optional, experimental, default false) Enables service worker that caches visited pages and resources for offline use.
36 | BookServiceWorker = true
37 |
--------------------------------------------------------------------------------
/content/_index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Introduction
3 | type: docs
4 | ---
5 |
6 | # Writing a book with Hugo hugo-book and Paged.js
7 |
8 | {{< columns >}}
9 | ## Hugo
10 |
11 | Such a cool framework!
12 |
13 | Using the [hugo-book theme](https://github.com/alex-shpak/hugo-book).
14 |
15 | Markdown files could be generated from R Markdown files.
16 |
17 | <--->
18 |
19 | ## paged.js
20 |
21 | Paged content, thus PDF, without LaTeX!
22 | {{< /columns >}}
23 |
24 |
25 | ## Beware
26 |
27 | This is a conceptual thing.
--------------------------------------------------------------------------------
/content/all/_index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: See PDF
3 | ---
4 |
--------------------------------------------------------------------------------
/content/docs/example/_index.md:
--------------------------------------------------------------------------------
1 | ---
2 | weight: 1
3 | bookFlatSection: true
4 | title: "Example Site"
5 | ---
6 |
7 | # Introduction
8 |
9 | ## Ferre hinnitibus erat accipitrem dixi Troiae tollens
10 |
11 | Lorem markdownum, a quoque nutu est *quodcumque mandasset* veluti. Passim
12 | inportuna totidemque nympha fert; repetens pendent, poenarum guttura sed vacet
13 | non, mortali undas. Omnis pharetramque gramen portentificisque membris servatum
14 | novabis fallit de nubibus atque silvas mihi. **Dixit repetitaque Quid**; verrit
15 | longa; sententia [mandat](http://pastor-ad.io/questussilvas) quascumque nescio
16 | solebat [litore](http://lacrimas-ab.net/); noctes. *Hostem haerentem* circuit
17 | [plenaque tamen](http://www.sine.io/in).
18 |
19 | - Pedum ne indigenae finire invergens carpebat
20 | - Velit posses summoque
21 | - De fumos illa foret
22 |
23 | ## Est simul fameque tauri qua ad
24 |
25 | Locum nullus nisi vomentes. Ab Persea sermone vela, miratur aratro; eandem
26 | Argolicas gener.
27 |
28 | ## Me sol
29 |
30 | Nec dis certa fuit socer, Nonacria **dies** manet tacitaque sibi? Sucis est
31 | iactata Castrumque iudex, et iactato quoque terraeque es tandem et maternos
32 | vittis. Lumina litus bene poenamque animos callem ne tuas in leones illam dea
33 | cadunt genus, et pleno nunc in quod. Anumque crescentesque sanguinis
34 | [progenies](http://www.late.net/alimentavirides) nuribus rustica tinguet. Pater
35 | omnes liquido creditis noctem.
36 |
37 | if (mirrored(icmp_dvd_pim, 3, smbMirroredHard) != lion(clickImportQueue,
38 | viralItunesBalancing, bankruptcy_file_pptp)) {
39 | file += ip_cybercrime_suffix;
40 | }
41 | if (runtimeSmartRom == netMarketingWord) {
42 | virusBalancingWin *= scriptPromptBespoke + raster(post_drive,
43 | windowsSli);
44 | cd = address_hertz_trojan;
45 | soap_ccd.pcbServerGigahertz(asp_hardware_isa, offlinePeopleware, nui);
46 | } else {
47 | megabyte.api = modem_flowchart - web + syntaxHalftoneAddress;
48 | }
49 | if (3 < mebibyteNetworkAnimated) {
50 | pharming_regular_error *= jsp_ribbon + algorithm * recycleMediaKindle(
51 | dvrSyntax, cdma);
52 | adf_sla *= hoverCropDrive;
53 | templateNtfs = -1 - vertical;
54 | } else {
55 | expressionCompressionVariable.bootMulti = white_eup_javascript(
56 | table_suffix);
57 | guidPpiPram.tracerouteLinux += rtfTerabyteQuicktime(1,
58 | managementRosetta(webcamActivex), 740874);
59 | }
60 | var virusTweetSsl = nullGigo;
61 |
62 | ## Trepident sitimque
63 |
64 | Sentiet et ferali errorem fessam, coercet superbus, Ascaniumque in pennis
65 | mediis; dolor? Vidit imi **Aeacon** perfida propositos adde, tua Somni Fluctibus
66 | errante lustrat non.
67 |
68 | Tamen inde, vos videt e flammis Scythica parantem rupisque pectora umbras. Haec
69 | ficta canistris repercusso simul ego aris Dixit! Esse Fama trepidare hunc
70 | crescendo vigor ululasse vertice *exspatiantur* celer tepidique petita aversata
71 | oculis iussa est me ferro.
72 |
--------------------------------------------------------------------------------
/content/docs/example/collapsed/3rd-level/4th-level.md:
--------------------------------------------------------------------------------
1 | # 4th Level of Menu
2 |
3 | ## Caesorum illa tu sentit micat vestes papyriferi
4 |
5 | Inde aderam facti; Theseus vis de tauri illa peream. Oculos **uberaque** non
6 | regisque vobis cursuque, opus venit quam vulnera. Et maiora necemque, lege modo;
7 | gestanda nitidi, vero? Dum ne pectoraque testantur.
8 |
9 | Venasque repulsa Samos qui, exspectatum eram animosque hinc, [aut
10 | manes](http://www.creveratnon.net/apricaaetheriis), Assyrii. Cupiens auctoribus
11 | pariter rubet, profana magni super nocens. Vos ius sibilat inpar turba visae
12 | iusto! Sedes ante dum superest **extrema**.
13 |
--------------------------------------------------------------------------------
/content/docs/example/collapsed/3rd-level/_index.md:
--------------------------------------------------------------------------------
1 | # 3rd Level of Menu
2 |
3 | Nefas discordemque domino montes numen tum humili nexilibusque exit, Iove. Quae
4 | miror esse, scelerisque Melaneus viribus. Miseri laurus. Hoc est proposita me
5 | ante aliquid, aura inponere candidioribus quidque accendit bella, sumpta.
6 | Intravit quam erat figentem hunc, motus de fontes parvo tempestate.
7 |
8 | iscsi_virus = pitch(json_in_on(eupViral),
9 | northbridge_services_troubleshooting, personal(
10 | firmware_rw.trash_rw_crm.device(interactive_gopher_personal,
11 | software, -1), megabit, ergonomicsSoftware(cmyk_usb_panel,
12 | mips_whitelist_duplex, cpa)));
13 | if (5) {
14 | managementNetwork += dma - boolean;
15 | kilohertz_token = 2;
16 | honeypot_affiliate_ergonomics = fiber;
17 | }
18 | mouseNorthbridge = byte(nybble_xmp_modem.horse_subnet(
19 | analogThroughputService * graphicPoint, drop(daw_bit, dnsIntranet),
20 | gateway_ospf), repository.domain_key.mouse(serverData(fileNetwork,
21 | trim_duplex_file), cellTapeDirect, token_tooltip_mashup(
22 | ripcordingMashup)));
23 | module_it = honeypot_driver(client_cold_dvr(593902, ripping_frequency) +
24 | coreLog.joystick(componentUdpLink), windows_expansion_touchscreen);
25 | bashGigabit.external.reality(2, server_hardware_codec.flops.ebookSampling(
26 | ciscNavigationBacklink, table + cleanDriver), indexProtocolIsp);
27 |
--------------------------------------------------------------------------------
/content/docs/example/collapsed/_index.md:
--------------------------------------------------------------------------------
1 | ---
2 | bookCollapseSection: true
3 | weight: 20
4 | ---
5 |
6 | # Collapsed Level of Menu
7 |
8 | ## Cognita laeva illo fracta
9 |
10 | Lorem markdownum pavent auras, surgit nunc cingentibus libet **Laomedonque que**
11 | est. Pastor [An](http://est.org/ire.aspx) arbor filia foedat, ne [fugit
12 | aliter](http://www.indiciumturbam.org/moramquid.php), per. Helicona illas et
13 | callida neptem est *Oresitrophos* caput, dentibus est venit. Tenet reddite
14 | [famuli](http://www.antro-et.net/) praesentem fortibus, quaeque vis foret si
15 | frondes *gelidos* gravidae circumtulit [inpulit armenta
16 | nativum](http://incurvasustulit.io/illi-virtute.html).
17 |
18 | 1. Te at cruciabere vides rubentis manebo
19 | 2. Maturuit in praetemptat ruborem ignara postquam habitasse
20 | 3. Subitarum supplevit quoque fontesque venabula spretis modo
21 | 4. Montis tot est mali quasque gravis
22 | 5. Quinquennem domus arsit ipse
23 | 6. Pellem turis pugnabant locavit
24 |
--------------------------------------------------------------------------------
/content/docs/example/hidden.md:
--------------------------------------------------------------------------------
1 | ---
2 | bookHidden: true
3 | ---
4 |
5 | # This page is hidden in menu
6 |
7 | # Quondam non pater est dignior ille Eurotas
8 |
9 | ## Latent te facies
10 |
11 | Lorem markdownum arma ignoscas vocavit quoque ille texit mandata mentis ultimus,
12 | frementes, qui in vel. Hippotades Peleus [pennas
13 | conscia](http://gratia.net/tot-qua.php) cuiquam Caeneus quas.
14 |
15 | - Pater demittere evincitque reddunt
16 | - Maxime adhuc pressit huc Danaas quid freta
17 | - Soror ego
18 | - Luctus linguam saxa ultroque prior Tatiumque inquit
19 | - Saepe liquitur subita superata dederat Anius sudor
20 |
21 | ## Cum honorum Latona
22 |
23 | O fallor [in sustinui
24 | iussorum](http://www.spectataharundine.org/aquas-relinquit.html) equidem.
25 | Nymphae operi oris alii fronde parens dumque, in auro ait mox ingenti proxima
26 | iamdudum maius?
27 |
28 | reality(burnDocking(apache_nanometer),
29 | pad.property_data_programming.sectorBrowserPpga(dataMask, 37,
30 | recycleRup));
31 | intellectualVaporwareUser += -5 * 4;
32 | traceroute_key_upnp /= lag_optical(android.smb(thyristorTftp));
33 | surge_host_golden = mca_compact_device(dual_dpi_opengl, 33,
34 | commerce_add_ppc);
35 | if (lun_ipv) {
36 | verticalExtranet(1, thumbnail_ttl, 3);
37 | bar_graphics_jpeg(chipset - sector_xmp_beta);
38 | }
39 |
40 | ## Fronde cetera dextrae sequens pennis voce muneris
41 |
42 | Acta cretus diem restet utque; move integer, oscula non inspirat, noctisque
43 | scelus! Nantemque in suas vobis quamvis, et labori!
44 |
45 | var runtimeDiskCompiler = home - array_ad_software;
46 | if (internic > disk) {
47 | emoticonLockCron += 37 + bps - 4;
48 | wan_ansi_honeypot.cardGigaflops = artificialStorageCgi;
49 | simplex -= downloadAccess;
50 | }
51 | var volumeHardeningAndroid = pixel + tftp + onProcessorUnmount;
52 | sector(memory(firewire + interlaced, wired));
--------------------------------------------------------------------------------
/content/docs/example/table-of-contents/_index.md:
--------------------------------------------------------------------------------
1 | ---
2 | weight: 10
3 | ---
4 |
5 | # Ubi loqui
6 |
7 | ## Mentem genus facietque salire tempus bracchia
8 |
9 | Lorem markdownum partu paterno Achillem. Habent amne generosi aderant ad pellem
10 | nec erat sustinet merces columque haec et, dixit minus nutrit accipiam subibis
11 | subdidit. Temeraria servatum agros qui sed fulva facta. Primum ultima, dedit,
12 | suo quisque linguae medentes fixo: tum petis.
13 |
14 | ## Rapit vocant si hunc siste adspice
15 |
16 | Ora precari Patraeque Neptunia, dixit Danae [Cithaeron
17 | armaque](http://mersis-an.org/litoristum) maxima in **nati Coniugis** templis
18 | fluidove. Effugit usus nec ingreditur agmen *ac manus* conlato. Nullis vagis
19 | nequiquam vultibus aliquos altera *suum venis* teneas fretum. Armos [remotis
20 | hoc](http://tutum.io/me) sine ferrea iuncta quam!
21 |
22 | ## Locus fuit caecis
23 |
24 | Nefas discordemque domino montes numen tum humili nexilibusque exit, Iove. Quae
25 | miror esse, scelerisque Melaneus viribus. Miseri laurus. Hoc est proposita me
26 | ante aliquid, aura inponere candidioribus quidque accendit bella, sumpta.
27 | Intravit quam erat figentem hunc, motus de fontes parvo tempestate.
28 |
29 | iscsi_virus = pitch(json_in_on(eupViral),
30 | northbridge_services_troubleshooting, personal(
31 | firmware_rw.trash_rw_crm.device(interactive_gopher_personal,
32 | software, -1), megabit, ergonomicsSoftware(cmyk_usb_panel,
33 | mips_whitelist_duplex, cpa)));
34 | if (5) {
35 | managementNetwork += dma - boolean;
36 | kilohertz_token = 2;
37 | honeypot_affiliate_ergonomics = fiber;
38 | }
39 | mouseNorthbridge = byte(nybble_xmp_modem.horse_subnet(
40 | analogThroughputService * graphicPoint, drop(daw_bit, dnsIntranet),
41 | gateway_ospf), repository.domain_key.mouse(serverData(fileNetwork,
42 | trim_duplex_file), cellTapeDirect, token_tooltip_mashup(
43 | ripcordingMashup)));
44 | module_it = honeypot_driver(client_cold_dvr(593902, ripping_frequency) +
45 | coreLog.joystick(componentUdpLink), windows_expansion_touchscreen);
46 | bashGigabit.external.reality(2, server_hardware_codec.flops.ebookSampling(
47 | ciscNavigationBacklink, table + cleanDriver), indexProtocolIsp);
48 |
49 | ## Placabilis coactis nega ingemuit ignoscat nimia non
50 |
51 | Frontis turba. Oculi gravis est Delphice; *inque praedaque* sanguine manu non.
52 |
53 | if (ad_api) {
54 | zif += usb.tiffAvatarRate(subnet, digital_rt) + exploitDrive;
55 | gigaflops(2 - bluetooth, edi_asp_memory.gopher(queryCursor, laptop),
56 | panel_point_firmware);
57 | spyware_bash.statePopApplet = express_netbios_digital(
58 | insertion_troubleshooting.brouter(recordFolderUs), 65);
59 | }
60 | recursionCoreRay = -5;
61 | if (hub == non) {
62 | portBoxVirus = soundWeb(recursive_card(rwTechnologyLeopard),
63 | font_radcab, guidCmsScalable + reciprocalMatrixPim);
64 | left.bug = screenshot;
65 | } else {
66 | tooltipOpacity = raw_process_permalink(webcamFontUser, -1);
67 | executable_router += tape;
68 | }
69 | if (tft) {
70 | bandwidthWeb *= social_page;
71 | } else {
72 | regular += 611883;
73 | thumbnail /= system_lag_keyboard;
74 | }
75 |
76 | ## Caesorum illa tu sentit micat vestes papyriferi
77 |
78 | Inde aderam facti; Theseus vis de tauri illa peream. Oculos **uberaque** non
79 | regisque vobis cursuque, opus venit quam vulnera. Et maiora necemque, lege modo;
80 | gestanda nitidi, vero? Dum ne pectoraque testantur.
81 |
82 | Venasque repulsa Samos qui, exspectatum eram animosque hinc, [aut
83 | manes](http://www.creveratnon.net/apricaaetheriis), Assyrii. Cupiens auctoribus
84 | pariter rubet, profana magni super nocens. Vos ius sibilat inpar turba visae
85 | iusto! Sedes ante dum superest **extrema**.
86 |
--------------------------------------------------------------------------------
/content/docs/example/table-of-contents/with-toc.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: With ToC
3 | weight: 1
4 | ---
5 | # Caput vino delphine in tamen vias
6 |
7 | ## Cognita laeva illo fracta
8 |
9 | Lorem markdownum pavent auras, surgit nunc cingentibus libet **Laomedonque que**
10 | est. Pastor [An](http://est.org/ire.aspx) arbor filia foedat, ne [fugit
11 | aliter](http://www.indiciumturbam.org/moramquid.php), per. Helicona illas et
12 | callida neptem est *Oresitrophos* caput, dentibus est venit. Tenet reddite
13 | [famuli](http://www.antro-et.net/) praesentem fortibus, quaeque vis foret si
14 | frondes *gelidos* gravidae circumtulit [inpulit armenta
15 | nativum](http://incurvasustulit.io/illi-virtute.html).
16 |
17 | 1. Te at cruciabere vides rubentis manebo
18 | 2. Maturuit in praetemptat ruborem ignara postquam habitasse
19 | 3. Subitarum supplevit quoque fontesque venabula spretis modo
20 | 4. Montis tot est mali quasque gravis
21 | 5. Quinquennem domus arsit ipse
22 | 6. Pellem turis pugnabant locavit
23 |
24 | ## Natus quaerere
25 |
26 | Pectora et sine mulcere, coniuge dum tincta incurvae. Quis iam; est dextra
27 | Peneosque, metuis a verba, primo. Illa sed colloque suis: magno: gramen, aera
28 | excutiunt concipit.
29 |
30 | > Phrygiae petendo suisque extimuit, super, pars quod audet! Turba negarem.
31 | > Fuerat attonitus; et dextra retinet sidera ulnas undas instimulat vacuae
32 | > generis? *Agnus* dabat et ignotis dextera, sic tibi pacis **feriente at mora**
33 | > euhoeque *comites hostem* vestras Phineus. Vultuque sanguine dominoque [metuit
34 | > risi](http://iuvat.org/eundem.php) fama vergit summaque meus clarissimus
35 | > artesque tinguebat successor nominis cervice caelicolae.
36 |
37 | ## Limitibus misere sit
38 |
39 | Aurea non fata repertis praerupit feruntur simul, meae hosti lentaque *citius
40 | levibus*, cum sede dixit, Phaethon texta. *Albentibus summos* multifidasque
41 | iungitur loquendi an pectore, mihi ursaque omnia adfata, aeno parvumque in animi
42 | perlucentes. Epytus agis ait vixque clamat ornum adversam spondet, quid sceptra
43 | ipsum **est**. Reseret nec; saeva suo passu debentia linguam terga et aures et
44 | cervix [de](http://www.amnem.io/pervenit.aspx) ubera. Coercet gelidumque manus,
45 | doluit volvitur induta?
46 |
47 | ## Enim sua
48 |
49 | Iuvenilior filia inlustre templa quidem herbis permittat trahens huic. In
50 | cruribus proceres sole crescitque *fata*, quos quos; merui maris se non tamen
51 | in, mea.
52 |
53 | ## Germana aves pignus tecta
54 |
55 | Mortalia rudibusque caelum cognosceret tantum aquis redito felicior texit, nec,
56 | aris parvo acre. Me parum contulerant multi tenentem, gratissime suis; vultum tu
57 | occupat deficeret corpora, sonum. E Actaea inplevit Phinea concepit nomenque
58 | potest sanguine captam nulla et, in duxisses campis non; mercede. Dicere cur
59 | Leucothoen obitum?
60 |
61 | Postibus mittam est *nubibus principium pluma*, exsecratur facta et. Iunge
62 | Mnemonidas pallamque pars; vere restitit alis flumina quae **quoque**, est
63 | ignara infestus Pyrrha. Di ducis terris maculatum At sede praemia manes
64 | nullaque!
65 |
--------------------------------------------------------------------------------
/content/docs/example/table-of-contents/without-toc.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Without ToC
3 | weight: 2
4 | bookToc: false
5 | ---
6 |
7 | # At me ipso nepotibus nunc celebratior genus
8 |
9 | ## Tanto oblite
10 |
11 | Lorem markdownum pectora novis patenti igne sua opus aurae feras materiaque
12 | illic demersit imago et aristas questaque posset. Vomit quoque suo inhaesuro
13 | clara. Esse cumque, per referri triste. Ut exponit solisque communis in tendens
14 | vincetis agisque iamque huic bene ante vetat omina Thebae rates. Aeacus servat
15 | admonitu concidit, ad resimas vultus et rugas vultu **dignamque** Siphnon.
16 |
17 | Quam iugulum regia simulacra, plus meruit humo pecorumque haesit, ab discedunt
18 | dixit: ritu pharetramque. Exul Laurenti orantem modo, per densum missisque labor
19 | manibus non colla unum, obiectat. Tu pervia collo, fessus quae Cretenque Myconon
20 | crate! Tegumenque quae invisi sudore per vocari quaque plus ventis fluidos. Nodo
21 | perque, fugisse pectora sorores.
22 |
23 | ## Summe promissa supple vadit lenius
24 |
25 | Quibus largis latebris aethera versato est, ait sentiat faciemque. Aequata alis
26 | nec Caeneus exululat inclite corpus est, ire **tibi** ostendens et tibi. Rigent
27 | et vires dique possent lumina; **eadem** dixit poma funeribus paret et felix
28 | reddebant ventis utile lignum.
29 |
30 | 1. Remansit notam Stygia feroxque
31 | 2. Et dabit materna
32 | 3. Vipereas Phrygiaeque umbram sollicito cruore conlucere suus
33 | 4. Quarum Elis corniger
34 | 5. Nec ieiunia dixit
35 |
36 | Vertitur mos ortu ramosam contudit dumque; placabat ac lumen. Coniunx Amoris
37 | spatium poenamque cavernis Thebae Pleiadasque ponunt, rapiare cum quae parum
38 | nimium rima.
39 |
40 | ## Quidem resupinus inducto solebat una facinus quae
41 |
42 | Credulitas iniqua praepetibus paruit prospexit, voce poena, sub rupit sinuatur,
43 | quin suum ventorumque arcadiae priori. Soporiferam erat formamque, fecit,
44 | invergens, nymphae mutat fessas ait finge.
45 |
46 | 1. Baculum mandataque ne addere capiti violentior
47 | 2. Altera duas quam hoc ille tenues inquit
48 | 3. Sicula sidereus latrantis domoque ratae polluit comites
49 | 4. Possit oro clausura namque se nunc iuvenisque
50 | 5. Faciem posuit
51 | 6. Quodque cum ponunt novercae nata vestrae aratra
52 |
53 | Ite extrema Phrygiis, patre dentibus, tonso perculit, enim blanda, manibus fide
54 | quos caput armis, posse! Nocendo fas Alcyonae lacertis structa ferarum manus
55 | fulmen dubius, saxa caelum effuge extremis fixum tumor adfecit **bella**,
56 | potentes? Dum nec insidiosa tempora tegit
57 | [spirarunt](http://mihiferre.net/iuvenes-peto.html). Per lupi pars foliis,
58 | porreximus humum negant sunt subposuere Sidone steterant auro. Memoraverit sine:
59 | ferrum idem Orion caelum heres gerebat fixis?
60 |
--------------------------------------------------------------------------------
/content/docs/shortcodes/_index.md:
--------------------------------------------------------------------------------
1 | ---
2 | bookFlatSection: true
3 | ---
4 |
--------------------------------------------------------------------------------
/content/docs/shortcodes/buttons.md:
--------------------------------------------------------------------------------
1 | # Buttons
2 |
3 | Buttons are styled links that can lead to local page or external link.
4 |
5 | ## Example
6 |
7 | ```tpl
8 | {{* button relref="/" [class="..."] */>}}Get Home{{* /button */>}}
9 | {{* button href="https://github.com/alex-shpak/hugo-book" */>}}Contribute{{* /button */>}}
10 | ```
11 |
12 | {{< button relref="/" >}}Get Home{{< /button >}}
13 | {{< button href="https://github.com/alex-shpak/hugo-book" >}}Contribute{{< /button >}}
14 |
--------------------------------------------------------------------------------
/content/docs/shortcodes/columns.md:
--------------------------------------------------------------------------------
1 | # Columns
2 |
3 | Columns help organize shorter pieces of content horizontally for readability.
4 |
5 |
6 | ```html
7 | {{* columns */>}}
8 | # Left Content
9 | Lorem markdownum insigne...
10 |
11 | <--->
12 |
13 | # Mid Content
14 | Lorem markdownum insigne...
15 |
16 | <--->
17 |
18 | # Right Content
19 | Lorem markdownum insigne...
20 | {{* /columns */>}}
21 | ```
22 |
23 | ## Example
24 |
25 | {{< columns >}}
26 | ## Left Content
27 | Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat
28 | stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
29 | protulit, sed sed aere valvis inhaesuro Pallas animam: qui _quid_, ignes.
30 | Miseratus fonte Ditis conubia.
31 |
32 | <--->
33 |
34 | ## Mid Content
35 | Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat
36 | stringit, frustra Saturnius uteroque inter!
37 |
38 | <--->
39 |
40 | ## Right Content
41 | Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat
42 | stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
43 | protulit, sed sed aere valvis inhaesuro Pallas animam: qui _quid_, ignes.
44 | Miseratus fonte Ditis conubia.
45 | {{< /columns >}}
46 |
--------------------------------------------------------------------------------
/content/docs/shortcodes/details.md:
--------------------------------------------------------------------------------
1 | # Details
2 |
3 | Details shortcode is a helper for `details` html5 element. It is going to replace `expand` shortcode.
4 |
5 | ## Example
6 | ```tpl
7 | {{* details "Title" [open] */>}}
8 | ## Markdown content
9 | Lorem markdownum insigne...
10 | {{* /details */>}}
11 | ```
12 | ```tpl
13 | {{* details title="Title" open=true */>}}
14 | ## Markdown content
15 | Lorem markdownum insigne...
16 | {{* /details */>}}
17 | ```
18 |
19 | {{< details "Title" open >}}
20 | ## Markdown content
21 | Lorem markdownum insigne...
22 | {{< /details >}}
23 |
--------------------------------------------------------------------------------
/content/docs/shortcodes/expand.md:
--------------------------------------------------------------------------------
1 | # Expand
2 |
3 | Expand shortcode can help to decrease clutter on screen by hiding part of text. Expand content by clicking on it.
4 |
5 | ## Example
6 | ### Default
7 |
8 | ```tpl
9 | {{* expand */>}}
10 | ## Markdown content
11 | Lorem markdownum insigne...
12 | {{* /expand */>}}
13 | ```
14 |
15 | {{< expand >}}
16 | ## Markdown content
17 | Lorem markdownum insigne...
18 | {{< /expand >}}
19 |
20 | ### With Custom Label
21 |
22 | ```tpl
23 | {{* expand "Custom Label" "..." */>}}
24 | ## Markdown content
25 | Lorem markdownum insigne...
26 | {{* /expand */>}}
27 | ```
28 |
29 | {{< expand "Custom Label" "..." >}}
30 | ## Markdown content
31 | Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat
32 | stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
33 | protulit, sed sed aere valvis inhaesuro Pallas animam: qui _quid_, ignes.
34 | Miseratus fonte Ditis conubia.
35 | {{< /expand >}}
36 |
--------------------------------------------------------------------------------
/content/docs/shortcodes/hints.md:
--------------------------------------------------------------------------------
1 | # Hints
2 |
3 | Hint shortcode can be used as hint/alerts/notification block.
4 | There are 3 colors to choose: `info`, `warning` and `danger`.
5 |
6 | ```tpl
7 | {{* hint [info|warning|danger] */>}}
8 | **Markdown content**
9 | Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat
10 | stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
11 | {{* /hint */>}}
12 | ```
13 |
14 | ## Example
15 |
16 | {{< hint info >}}
17 | **Markdown content**
18 | Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat
19 | stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
20 | {{< /hint >}}
21 |
22 | {{< hint warning >}}
23 | **Markdown content**
24 | Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat
25 | stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
26 | {{< /hint >}}
27 |
28 | {{< hint danger >}}
29 | **Markdown content**
30 | Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat
31 | stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
32 | {{< /hint >}}
33 |
--------------------------------------------------------------------------------
/content/docs/shortcodes/katex.md:
--------------------------------------------------------------------------------
1 | # KaTeX
2 |
3 | KaTeX shortcode let you render math typesetting in markdown document. See [KaTeX](https://katex.org/)
4 |
5 | ## Example
6 | {{< columns >}}
7 |
8 | ```latex
9 | {{* katex [display] [class="text-center"] */>}}
10 | f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi
11 | {{* /katex */>}}
12 | ```
13 |
14 | <--->
15 |
16 | {{< katex display >}}
17 | f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi
18 | {{< /katex >}}
19 |
20 | {{< /columns >}}
21 |
22 | ## Display Mode Example
23 |
24 | Here is some inline example: {{< katex >}}\pi(x){{< /katex >}}, rendered in the same line. And below is `display` example, having `display: block`
25 | {{< katex display >}}
26 | f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi
27 | {{< /katex >}}
28 | Text continues here.
29 |
--------------------------------------------------------------------------------
/content/docs/shortcodes/mermaid.md:
--------------------------------------------------------------------------------
1 | # Mermaid Chart
2 |
3 | [Mermaid](https://mermaidjs.github.io/) is library for generating svg charts and diagrams from text.
4 |
5 | ## Example
6 |
7 | {{< columns >}}
8 | ```tpl
9 | {{* mermaid [class="text-center"]*/>}}
10 | sequenceDiagram
11 | Alice->>Bob: Hello Bob, how are you?
12 | alt is sick
13 | Bob->>Alice: Not so good :(
14 | else is well
15 | Bob->>Alice: Feeling fresh like a daisy
16 | end
17 | opt Extra response
18 | Bob->>Alice: Thanks for asking
19 | end
20 | {{* /mermaid */>}}
21 | ```
22 |
23 | <--->
24 |
25 | {{< mermaid >}}
26 | sequenceDiagram
27 | Alice->>Bob: Hello Bob, how are you?
28 | alt is sick
29 | Bob->>Alice: Not so good :(
30 | else is well
31 | Bob->>Alice: Feeling fresh like a daisy
32 | end
33 | opt Extra response
34 | Bob->>Alice: Thanks for asking
35 | end
36 | {{< /mermaid >}}
37 |
38 | {{< /columns >}}
39 |
--------------------------------------------------------------------------------
/content/docs/shortcodes/tabs.md:
--------------------------------------------------------------------------------
1 | # Tabs
2 |
3 | Tabs let you organize content by context, for example installation instructions for each supported platform.
4 |
5 | ```tpl
6 | {{* tabs "uniqueid" */>}}
7 | {{* tab "MacOS" */>}} # MacOS Content {{* /tab */>}}
8 | {{* tab "Linux" */>}} # Linux Content {{* /tab */>}}
9 | {{* tab "Windows" */>}} # Windows Content {{* /tab */>}}
10 | {{* /tabs */>}}
11 | ```
12 |
13 | ## Example
14 |
15 | {{< tabs "uniqueid" >}}
16 | {{< tab "MacOS" >}}
17 | # MacOS
18 |
19 | This is tab **MacOS** content.
20 |
21 | Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat
22 | stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
23 | protulit, sed sed aere valvis inhaesuro Pallas animam: qui _quid_, ignes.
24 | Miseratus fonte Ditis conubia.
25 | {{< /tab >}}
26 |
27 | {{< tab "Linux" >}}
28 |
29 | # Linux
30 |
31 | This is tab **Linux** content.
32 |
33 | Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat
34 | stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
35 | protulit, sed sed aere valvis inhaesuro Pallas animam: qui _quid_, ignes.
36 | Miseratus fonte Ditis conubia.
37 | {{< /tab >}}
38 |
39 | {{< tab "Windows" >}}
40 |
41 | # Windows
42 |
43 | This is tab **Windows** content.
44 |
45 | Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat
46 | stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
47 | protulit, sed sed aere valvis inhaesuro Pallas animam: qui _quid_, ignes.
48 | Miseratus fonte Ditis conubia.
49 | {{< /tab >}}
50 | {{< /tabs >}}
51 |
--------------------------------------------------------------------------------
/content/menu/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | headless: true
3 | ---
4 |
5 | - [**Example Site**]({{< relref "/docs/example" >}})
6 | - [Table of Contents]({{< relref "/docs/example/table-of-contents" >}})
7 | - [With ToC]({{< relref "/docs/example/table-of-contents/with-toc" >}})
8 | - [Without ToC]({{< relref "/docs/example/table-of-contents/without-toc" >}})
9 | - [Collapsed]({{< relref "/docs/example/collapsed" >}})
10 | - [3rd]({{< relref "/docs/example/collapsed/3rd-level" >}})
11 | - [4th]({{< relref "/docs/example/collapsed/3rd-level/4th-level" >}})
12 |
13 |
14 | - **Shortcodes**
15 | - [Buttons]({{< relref "/docs/shortcodes/buttons" >}})
16 | - [Columns]({{< relref "/docs/shortcodes/columns" >}})
17 | - [Expand]({{< relref "/docs/shortcodes/expand" >}})
18 | - [Hints]({{< relref "/docs/shortcodes/hints" >}})
19 | - [Katex]({{< relref "/docs/shortcodes/katex" >}})
20 | - [Mermaid]({{< relref "/docs/shortcodes/mermaid" >}})
21 | - [Tabs]({{< relref "/docs/shortcodes/tabs" >}})
22 |
23 |
--------------------------------------------------------------------------------
/content/posts/_index.md:
--------------------------------------------------------------------------------
1 | ---
2 | menu:
3 | after:
4 | name: blog
5 | weight: 5
6 | title: Blog
7 | ---
8 |
--------------------------------------------------------------------------------
/content/posts/creating-a-new-theme.md:
--------------------------------------------------------------------------------
1 | ---
2 | author: "Michael Henderson"
3 | date: 2014-09-28
4 | linktitle: Creating a New Theme
5 | menu:
6 | main:
7 | parent: tutorials
8 | next: /tutorials/github-pages-blog
9 | prev: /tutorials/automated-deployments
10 | title: Creating a New Theme
11 | weight: 10
12 | ---
13 |
14 |
15 | ## Introduction
16 |
17 | This tutorial will show you how to create a simple theme in Hugo. I assume that you are familiar with HTML, the bash command line, and that you are comfortable using Markdown to format content. I'll explain how Hugo uses templates and how you can organize your templates to create a theme. I won't cover using CSS to style your theme.
18 |
19 | We'll start with creating a new site with a very basic template. Then we'll add in a few pages and posts. With small variations on that, you will be able to create many different types of web sites.
20 |
21 | In this tutorial, commands that you enter will start with the "$" prompt. The output will follow. Lines that start with "#" are comments that I've added to explain a point. When I show updates to a file, the ":wq" on the last line means to save the file.
22 |
23 | Here's an example:
24 |
25 | ```
26 | ## this is a comment
27 | $ echo this is a command
28 | this is a command
29 |
30 | ## edit the file
31 | $ vi foo.md
32 | +++
33 | date = "2014-09-28"
34 | title = "creating a new theme"
35 | +++
36 |
37 | bah and humbug
38 | :wq
39 |
40 | ## show it
41 | $ cat foo.md
42 | +++
43 | date = "2014-09-28"
44 | title = "creating a new theme"
45 | +++
46 |
47 | bah and humbug
48 | $
49 | ```
50 |
51 |
52 | ## Some Definitions
53 |
54 | There are a few concepts that you need to understand before creating a theme.
55 |
56 | ### Skins
57 |
58 | Skins are the files responsible for the look and feel of your site. It’s the CSS that controls colors and fonts, it’s the Javascript that determines actions and reactions. It’s also the rules that Hugo uses to transform your content into the HTML that the site will serve to visitors.
59 |
60 | You have two ways to create a skin. The simplest way is to create it in the ```layouts/``` directory. If you do, then you don’t have to worry about configuring Hugo to recognize it. The first place that Hugo will look for rules and files is in the ```layouts/``` directory so it will always find the skin.
61 |
62 | Your second choice is to create it in a sub-directory of the ```themes/``` directory. If you do, then you must always tell Hugo where to search for the skin. It’s extra work, though, so why bother with it?
63 |
64 | The difference between creating a skin in ```layouts/``` and creating it in ```themes/``` is very subtle. A skin in ```layouts/``` can’t be customized without updating the templates and static files that it is built from. A skin created in ```themes/```, on the other hand, can be and that makes it easier for other people to use it.
65 |
66 | The rest of this tutorial will call a skin created in the ```themes/``` directory a theme.
67 |
68 | Note that you can use this tutorial to create a skin in the ```layouts/``` directory if you wish to. The main difference will be that you won’t need to update the site’s configuration file to use a theme.
69 |
70 | ### The Home Page
71 |
72 | The home page, or landing page, is the first page that many visitors to a site see. It is the index.html file in the root directory of the web site. Since Hugo writes files to the public/ directory, our home page is public/index.html.
73 |
74 | ### Site Configuration File
75 |
76 | When Hugo runs, it looks for a configuration file that contains settings that override default values for the entire site. The file can use TOML, YAML, or JSON. I prefer to use TOML for my configuration files. If you prefer to use JSON or YAML, you’ll need to translate my examples. You’ll also need to change the name of the file since Hugo uses the extension to determine how to process it.
77 |
78 | Hugo translates Markdown files into HTML. By default, Hugo expects to find Markdown files in your ```content/``` directory and template files in your ```themes/``` directory. It will create HTML files in your ```public/``` directory. You can change this by specifying alternate locations in the configuration file.
79 |
80 | ### Content
81 |
82 | Content is stored in text files that contain two sections. The first section is the “front matter,” which is the meta-information on the content. The second section contains Markdown that will be converted to HTML.
83 |
84 | #### Front Matter
85 |
86 | The front matter is information about the content. Like the configuration file, it can be written in TOML, YAML, or JSON. Unlike the configuration file, Hugo doesn’t use the file’s extension to know the format. It looks for markers to signal the type. TOML is surrounded by “`+++`”, YAML by “`---`”, and JSON is enclosed in curly braces. I prefer to use TOML, so you’ll need to translate my examples if you prefer YAML or JSON.
87 |
88 | The information in the front matter is passed into the template before the content is rendered into HTML.
89 |
90 | #### Markdown
91 |
92 | Content is written in Markdown which makes it easier to create the content. Hugo runs the content through a Markdown engine to create the HTML which will be written to the output file.
93 |
94 | ### Template Files
95 |
96 | Hugo uses template files to render content into HTML. Template files are a bridge between the content and presentation. Rules in the template define what content is published, where it's published to, and how it will rendered to the HTML file. The template guides the presentation by specifying the style to use.
97 |
98 | There are three types of templates: single, list, and partial. Each type takes a bit of content as input and transforms it based on the commands in the template.
99 |
100 | Hugo uses its knowledge of the content to find the template file used to render the content. If it can’t find a template that is an exact match for the content, it will shift up a level and search from there. It will continue to do so until it finds a matching template or runs out of templates to try. If it can’t find a template, it will use the default template for the site.
101 |
102 | Please note that you can use the front matter to influence Hugo’s choice of templates.
103 |
104 | #### Single Template
105 |
106 | A single template is used to render a single piece of content. For example, an article or post would be a single piece of content and use a single template.
107 |
108 | #### List Template
109 |
110 | A list template renders a group of related content. That could be a summary of recent postings or all articles in a category. List templates can contain multiple groups.
111 |
112 | The homepage template is a special type of list template. Hugo assumes that the home page of your site will act as the portal for the rest of the content in the site.
113 |
114 | #### Partial Template
115 |
116 | A partial template is a template that can be included in other templates. Partial templates must be called using the “partial” template command. They are very handy for rolling up common behavior. For example, your site may have a banner that all pages use. Instead of copying the text of the banner into every single and list template, you could create a partial with the banner in it. That way if you decide to change the banner, you only have to change the partial template.
117 |
118 | ## Create a New Site
119 |
120 | Let's use Hugo to create a new web site. I'm a Mac user, so I'll create mine in my home directory, in the Sites folder. If you're using Linux, you might have to create the folder first.
121 |
122 | The "new site" command will create a skeleton of a site. It will give you the basic directory structure and a useable configuration file.
123 |
124 | ```
125 | $ hugo new site ~/Sites/zafta
126 | $ cd ~/Sites/zafta
127 | $ ls -l
128 | total 8
129 | drwxr-xr-x 7 quoha staff 238 Sep 29 16:49 .
130 | drwxr-xr-x 3 quoha staff 102 Sep 29 16:49 ..
131 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 archetypes
132 | -rw-r--r-- 1 quoha staff 82 Sep 29 16:49 config.toml
133 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 content
134 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 layouts
135 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 static
136 | $
137 | ```
138 |
139 | Take a look in the content/ directory to confirm that it is empty.
140 |
141 | The other directories (archetypes/, layouts/, and static/) are used when customizing a theme. That's a topic for a different tutorial, so please ignore them for now.
142 |
143 | ### Generate the HTML For the New Site
144 |
145 | Running the `hugo` command with no options will read all the available content and generate the HTML files. It will also copy all static files (that's everything that's not content). Since we have an empty site, it won't do much, but it will do it very quickly.
146 |
147 | ```
148 | $ hugo --verbose
149 | INFO: 2014/09/29 Using config file: config.toml
150 | INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/static/ to /Users/quoha/Sites/zafta/public/
151 | WARN: 2014/09/29 Unable to locate layout: [index.html _default/list.html _default/single.html]
152 | WARN: 2014/09/29 Unable to locate layout: [404.html]
153 | 0 draft content
154 | 0 future content
155 | 0 pages created
156 | 0 tags created
157 | 0 categories created
158 | in 2 ms
159 | $
160 | ```
161 |
162 | The "`--verbose`" flag gives extra information that will be helpful when we build the template. Every line of the output that starts with "INFO:" or "WARN:" is present because we used that flag. The lines that start with "WARN:" are warning messages. We'll go over them later.
163 |
164 | We can verify that the command worked by looking at the directory again.
165 |
166 | ```
167 | $ ls -l
168 | total 8
169 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 archetypes
170 | -rw-r--r-- 1 quoha staff 82 Sep 29 16:49 config.toml
171 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 content
172 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 layouts
173 | drwxr-xr-x 4 quoha staff 136 Sep 29 17:02 public
174 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 static
175 | $
176 | ```
177 |
178 | See that new public/ directory? Hugo placed all generated content there. When you're ready to publish your web site, that's the place to start. For now, though, let's just confirm that we have what we'd expect from a site with no content.
179 |
180 | ```
181 | $ ls -l public
182 | total 16
183 | -rw-r--r-- 1 quoha staff 416 Sep 29 17:02 index.xml
184 | -rw-r--r-- 1 quoha staff 262 Sep 29 17:02 sitemap.xml
185 | $
186 | ```
187 |
188 | Hugo created two XML files, which is standard, but there are no HTML files.
189 |
190 |
191 |
192 | ### Test the New Site
193 |
194 | Verify that you can run the built-in web server. It will dramatically shorten your development cycle if you do. Start it by running the "server" command. If it is successful, you will see output similar to the following:
195 |
196 | ```
197 | $ hugo server --verbose
198 | INFO: 2014/09/29 Using config file: /Users/quoha/Sites/zafta/config.toml
199 | INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/static/ to /Users/quoha/Sites/zafta/public/
200 | WARN: 2014/09/29 Unable to locate layout: [index.html _default/list.html _default/single.html]
201 | WARN: 2014/09/29 Unable to locate layout: [404.html]
202 | 0 draft content
203 | 0 future content
204 | 0 pages created
205 | 0 tags created
206 | 0 categories created
207 | in 2 ms
208 | Serving pages from /Users/quoha/Sites/zafta/public
209 | Web Server is available at http://localhost:1313
210 | Press Ctrl+C to stop
211 | ```
212 |
213 | Connect to the listed URL (it's on the line that starts with "Web Server"). If everything is working correctly, you should get a page that shows the following:
214 |
215 | ```
216 | index.xml
217 | sitemap.xml
218 | ```
219 |
220 | That's a listing of your public/ directory. Hugo didn't create a home page because our site has no content. When there's no index.html file in a directory, the server lists the files in the directory, which is what you should see in your browser.
221 |
222 | Let’s go back and look at those warnings again.
223 |
224 | ```
225 | WARN: 2014/09/29 Unable to locate layout: [index.html _default/list.html _default/single.html]
226 | WARN: 2014/09/29 Unable to locate layout: [404.html]
227 | ```
228 |
229 | That second warning is easier to explain. We haven’t created a template to be used to generate “page not found errors.” The 404 message is a topic for a separate tutorial.
230 |
231 | Now for the first warning. It is for the home page. You can tell because the first layout that it looked for was “index.html.” That’s only used by the home page.
232 |
233 | I like that the verbose flag causes Hugo to list the files that it's searching for. For the home page, they are index.html, _default/list.html, and _default/single.html. There are some rules that we'll cover later that explain the names and paths. For now, just remember that Hugo couldn't find a template for the home page and it told you so.
234 |
235 | At this point, you've got a working installation and site that we can build upon. All that’s left is to add some content and a theme to display it.
236 |
237 | ## Create a New Theme
238 |
239 | Hugo doesn't ship with a default theme. There are a few available (I counted a dozen when I first installed Hugo) and Hugo comes with a command to create new themes.
240 |
241 | We're going to create a new theme called "zafta." Since the goal of this tutorial is to show you how to fill out the files to pull in your content, the theme will not contain any CSS. In other words, ugly but functional.
242 |
243 | All themes have opinions on content and layout. For example, Zafta uses "post" over "blog". Strong opinions make for simpler templates but differing opinions make it tougher to use themes. When you build a theme, consider using the terms that other themes do.
244 |
245 |
246 | ### Create a Skeleton
247 |
248 | Use the hugo "new" command to create the skeleton of a theme. This creates the directory structure and places empty files for you to fill out.
249 |
250 | ```
251 | $ hugo new theme zafta
252 |
253 | $ ls -l
254 | total 8
255 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 archetypes
256 | -rw-r--r-- 1 quoha staff 82 Sep 29 16:49 config.toml
257 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 content
258 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 layouts
259 | drwxr-xr-x 4 quoha staff 136 Sep 29 17:02 public
260 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 static
261 | drwxr-xr-x 3 quoha staff 102 Sep 29 17:31 themes
262 |
263 | $ find themes -type f | xargs ls -l
264 | -rw-r--r-- 1 quoha staff 1081 Sep 29 17:31 themes/zafta/LICENSE.md
265 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/archetypes/default.md
266 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/_default/list.html
267 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/_default/single.html
268 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/index.html
269 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/partials/footer.html
270 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/partials/header.html
271 | -rw-r--r-- 1 quoha staff 93 Sep 29 17:31 themes/zafta/theme.toml
272 | $
273 | ```
274 |
275 | The skeleton includes templates (the files ending in .html), license file, a description of your theme (the theme.toml file), and an empty archetype.
276 |
277 | Please take a minute to fill out the theme.toml and LICENSE.md files. They're optional, but if you're going to be distributing your theme, it tells the world who to praise (or blame). It's also nice to declare the license so that people will know how they can use the theme.
278 |
279 | ```
280 | $ vi themes/zafta/theme.toml
281 | author = "michael d henderson"
282 | description = "a minimal working template"
283 | license = "MIT"
284 | name = "zafta"
285 | source_repo = ""
286 | tags = ["tags", "categories"]
287 | :wq
288 |
289 | ## also edit themes/zafta/LICENSE.md and change
290 | ## the bit that says "YOUR_NAME_HERE"
291 | ```
292 |
293 | Note that the the skeleton's template files are empty. Don't worry, we'll be changing that shortly.
294 |
295 | ```
296 | $ find themes/zafta -name '*.html' | xargs ls -l
297 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/_default/list.html
298 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/_default/single.html
299 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/index.html
300 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/partials/footer.html
301 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/partials/header.html
302 | $
303 | ```
304 |
305 |
306 |
307 | ### Update the Configuration File to Use the Theme
308 |
309 | Now that we've got a theme to work with, it's a good idea to add the theme name to the configuration file. This is optional, because you can always add "-t zafta" on all your commands. I like to put it the configuration file because I like shorter command lines. If you don't put it in the configuration file or specify it on the command line, you won't use the template that you're expecting to.
310 |
311 | Edit the file to add the theme, add a title for the site, and specify that all of our content will use the TOML format.
312 |
313 | ```
314 | $ vi config.toml
315 | theme = "zafta"
316 | baseurl = ""
317 | languageCode = "en-us"
318 | title = "zafta - totally refreshing"
319 | MetaDataFormat = "toml"
320 | :wq
321 |
322 | $
323 | ```
324 |
325 | ### Generate the Site
326 |
327 | Now that we have an empty theme, let's generate the site again.
328 |
329 | ```
330 | $ hugo --verbose
331 | INFO: 2014/09/29 Using config file: /Users/quoha/Sites/zafta/config.toml
332 | INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/themes/zafta/static/ to /Users/quoha/Sites/zafta/public/
333 | INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/static/ to /Users/quoha/Sites/zafta/public/
334 | WARN: 2014/09/29 Unable to locate layout: [404.html theme/404.html]
335 | 0 draft content
336 | 0 future content
337 | 0 pages created
338 | 0 tags created
339 | 0 categories created
340 | in 2 ms
341 | $
342 | ```
343 |
344 | Did you notice that the output is different? The warning message for the home page has disappeared and we have an additional information line saying that Hugo is syncing from the theme's directory.
345 |
346 | Let's check the public/ directory to see what Hugo's created.
347 |
348 | ```
349 | $ ls -l public
350 | total 16
351 | drwxr-xr-x 2 quoha staff 68 Sep 29 17:56 css
352 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:56 index.html
353 | -rw-r--r-- 1 quoha staff 407 Sep 29 17:56 index.xml
354 | drwxr-xr-x 2 quoha staff 68 Sep 29 17:56 js
355 | -rw-r--r-- 1 quoha staff 243 Sep 29 17:56 sitemap.xml
356 | $
357 | ```
358 |
359 | Notice four things:
360 |
361 | 1. Hugo created a home page. This is the file public/index.html.
362 | 2. Hugo created a css/ directory.
363 | 3. Hugo created a js/ directory.
364 | 4. Hugo claimed that it created 0 pages. It created a file and copied over static files, but didn't create any pages. That's because it considers a "page" to be a file created directly from a content file. It doesn't count things like the index.html files that it creates automatically.
365 |
366 | #### The Home Page
367 |
368 | Hugo supports many different types of templates. The home page is special because it gets its own type of template and its own template file. The file, layouts/index.html, is used to generate the HTML for the home page. The Hugo documentation says that this is the only required template, but that depends. Hugo's warning message shows that it looks for three different templates:
369 |
370 | ```
371 | WARN: 2014/09/29 Unable to locate layout: [index.html _default/list.html _default/single.html]
372 | ```
373 |
374 | If it can't find any of these, it completely skips creating the home page. We noticed that when we built the site without having a theme installed.
375 |
376 | When Hugo created our theme, it created an empty home page template. Now, when we build the site, Hugo finds the template and uses it to generate the HTML for the home page. Since the template file is empty, the HTML file is empty, too. If the template had any rules in it, then Hugo would have used them to generate the home page.
377 |
378 | ```
379 | $ find . -name index.html | xargs ls -l
380 | -rw-r--r-- 1 quoha staff 0 Sep 29 20:21 ./public/index.html
381 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 ./themes/zafta/layouts/index.html
382 | $
383 | ```
384 |
385 | #### The Magic of Static
386 |
387 | Hugo does two things when generating the site. It uses templates to transform content into HTML and it copies static files into the site. Unlike content, static files are not transformed. They are copied exactly as they are.
388 |
389 | Hugo assumes that your site will use both CSS and JavaScript, so it creates directories in your theme to hold them. Remember opinions? Well, Hugo's opinion is that you'll store your CSS in a directory named css/ and your JavaScript in a directory named js/. If you don't like that, you can change the directory names in your theme directory or even delete them completely. Hugo's nice enough to offer its opinion, then behave nicely if you disagree.
390 |
391 | ```
392 | $ find themes/zafta -type d | xargs ls -ld
393 | drwxr-xr-x 7 quoha staff 238 Sep 29 17:38 themes/zafta
394 | drwxr-xr-x 3 quoha staff 102 Sep 29 17:31 themes/zafta/archetypes
395 | drwxr-xr-x 5 quoha staff 170 Sep 29 17:31 themes/zafta/layouts
396 | drwxr-xr-x 4 quoha staff 136 Sep 29 17:31 themes/zafta/layouts/_default
397 | drwxr-xr-x 4 quoha staff 136 Sep 29 17:31 themes/zafta/layouts/partials
398 | drwxr-xr-x 4 quoha staff 136 Sep 29 17:31 themes/zafta/static
399 | drwxr-xr-x 2 quoha staff 68 Sep 29 17:31 themes/zafta/static/css
400 | drwxr-xr-x 2 quoha staff 68 Sep 29 17:31 themes/zafta/static/js
401 | $
402 | ```
403 |
404 | ## The Theme Development Cycle
405 |
406 | When you're working on a theme, you will make changes in the theme's directory, rebuild the site, and check your changes in the browser. Hugo makes this very easy:
407 |
408 | 1. Purge the public/ directory.
409 | 2. Run the built in web server in watch mode.
410 | 3. Open your site in a browser.
411 | 4. Update the theme.
412 | 5. Glance at your browser window to see changes.
413 | 6. Return to step 4.
414 |
415 | I’ll throw in one more opinion: never work on a theme on a live site. Always work on a copy of your site. Make changes to your theme, test them, then copy them up to your site. For added safety, use a tool like Git to keep a revision history of your content and your theme. Believe me when I say that it is too easy to lose both your mind and your changes.
416 |
417 | Check the main Hugo site for information on using Git with Hugo.
418 |
419 | ### Purge the public/ Directory
420 |
421 | When generating the site, Hugo will create new files and update existing ones in the ```public/``` directory. It will not delete files that are no longer used. For example, files that were created in the wrong directory or with the wrong title will remain. If you leave them, you might get confused by them later. I recommend cleaning out your site prior to generating it.
422 |
423 | Note: If you're building on an SSD, you should ignore this. Churning on a SSD can be costly.
424 |
425 | ### Hugo's Watch Option
426 |
427 | Hugo's "`--watch`" option will monitor the content/ and your theme directories for changes and rebuild the site automatically.
428 |
429 | ### Live Reload
430 |
431 | Hugo's built in web server supports live reload. As pages are saved on the server, the browser is told to refresh the page. Usually, this happens faster than you can say, "Wow, that's totally amazing."
432 |
433 | ### Development Commands
434 |
435 | Use the following commands as the basis for your workflow.
436 |
437 | ```
438 | ## purge old files. hugo will recreate the public directory.
439 | ##
440 | $ rm -rf public
441 | ##
442 | ## run hugo in watch mode
443 | ##
444 | $ hugo server --watch --verbose
445 | ```
446 |
447 | Here's sample output showing Hugo detecting a change to the template for the home page. Once generated, the web browser automatically reloaded the page. I've said this before, it's amazing.
448 |
449 |
450 | ```
451 | $ rm -rf public
452 | $ hugo server --watch --verbose
453 | INFO: 2014/09/29 Using config file: /Users/quoha/Sites/zafta/config.toml
454 | INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/themes/zafta/static/ to /Users/quoha/Sites/zafta/public/
455 | INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/static/ to /Users/quoha/Sites/zafta/public/
456 | WARN: 2014/09/29 Unable to locate layout: [404.html theme/404.html]
457 | 0 draft content
458 | 0 future content
459 | 0 pages created
460 | 0 tags created
461 | 0 categories created
462 | in 2 ms
463 | Watching for changes in /Users/quoha/Sites/zafta/content
464 | Serving pages from /Users/quoha/Sites/zafta/public
465 | Web Server is available at http://localhost:1313
466 | Press Ctrl+C to stop
467 | INFO: 2014/09/29 File System Event: ["/Users/quoha/Sites/zafta/themes/zafta/layouts/index.html": MODIFY|ATTRIB]
468 | Change detected, rebuilding site
469 |
470 | WARN: 2014/09/29 Unable to locate layout: [404.html theme/404.html]
471 | 0 draft content
472 | 0 future content
473 | 0 pages created
474 | 0 tags created
475 | 0 categories created
476 | in 1 ms
477 | ```
478 |
479 | ## Update the Home Page Template
480 |
481 | The home page is one of a few special pages that Hugo creates automatically. As mentioned earlier, it looks for one of three files in the theme's layout/ directory:
482 |
483 | 1. index.html
484 | 2. _default/list.html
485 | 3. _default/single.html
486 |
487 | We could update one of the default templates, but a good design decision is to update the most specific template available. That's not a hard and fast rule (in fact, we'll break it a few times in this tutorial), but it is a good generalization.
488 |
489 | ### Make a Static Home Page
490 |
491 | Right now, that page is empty because we don't have any content and we don't have any logic in the template. Let's change that by adding some text to the template.
492 |
493 | ```
494 | $ vi themes/zafta/layouts/index.html
495 |
496 |
497 |
hugo says hello!
499 | 500 | 501 | :wq 502 | 503 | $ 504 | ``` 505 | 506 | Build the web site and then verify the results. 507 | 508 | ``` 509 | $ hugo --verbose 510 | INFO: 2014/09/29 Using config file: /Users/quoha/Sites/zafta/config.toml 511 | INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/themes/zafta/static/ to /Users/quoha/Sites/zafta/public/ 512 | INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/static/ to /Users/quoha/Sites/zafta/public/ 513 | WARN: 2014/09/29 Unable to locate layout: [404.html theme/404.html] 514 | 0 draft content 515 | 0 future content 516 | 0 pages created 517 | 0 tags created 518 | 0 categories created 519 | in 2 ms 520 | 521 | $ find public -type f -name '*.html' | xargs ls -l 522 | -rw-r--r-- 1 quoha staff 78 Sep 29 21:26 public/index.html 523 | 524 | $ cat public/index.html 525 | 526 | 527 | 528 |hugo says hello!
529 | 530 | ``` 531 | 532 | #### Live Reload 533 | 534 | Note: If you're running the server with the `--watch` option, you'll see different content in the file: 535 | 536 | ``` 537 | $ cat public/index.html 538 | 539 | 540 | 541 |hugo says hello!
542 | 546 | 547 | ``` 548 | 549 | When you use `--watch`, the Live Reload script is added by Hugo. Look for live reload in the documentation to see what it does and how to disable it. 550 | 551 | ### Build a "Dynamic" Home Page 552 | 553 | "Dynamic home page?" Hugo's a static web site generator, so this seems an odd thing to say. I mean let's have the home page automatically reflect the content in the site every time Hugo builds it. We'll use iteration in the template to do that. 554 | 555 | #### Create New Posts 556 | 557 | Now that we have the home page generating static content, let's add some content to the site. We'll display these posts as a list on the home page and on their own page, too. 558 | 559 | Hugo has a command to generate a skeleton post, just like it does for sites and themes. 560 | 561 | ``` 562 | $ hugo --verbose new post/first.md 563 | INFO: 2014/09/29 Using config file: /Users/quoha/Sites/zafta/config.toml 564 | INFO: 2014/09/29 attempting to create post/first.md of post 565 | INFO: 2014/09/29 curpath: /Users/quoha/Sites/zafta/themes/zafta/archetypes/default.md 566 | ERROR: 2014/09/29 Unable to Castmy first post
814 | 815 | 816 | 817 | 818 | $ cat public/post/second/index.html 819 | 820 | 821 | 822 |my second post
827 | 828 | 829 | 830 | $ 831 | ``` 832 | 833 | Notice that the posts now have content. You can go to localhost:1313/post/first to verify. 834 | 835 | ### Linking to Content 836 | 837 | The posts are on the home page. Let's add a link from there to the post. Since this is the home page, we'll update its template. 838 | 839 | ``` 840 | $ vi themes/zafta/layouts/index.html 841 | 842 | 843 | 844 | {{ range first 10 .Data.Pages }} 845 |