Skip to content

Commit b42c932

Browse files
committed
markup/asciidocext: Improve Asciidoctor integration
Fixes an issue where improper attribute derivation from the page's relative permalink caused failures with `outdir`, `imagesoutdir`, and `imagesdir` when `markup.asciidocext.workingFolderCurrent` is enabled. The updated logic now correctly handles: - Multi-byte characters - Multilingual multi-host sites - Site builds from a subdirectory - Pages using ugly URLs Supports diagram caching as implemented in v3.1.0 of the asciidoctor-diagram extension: - Enables caching by default - Sets default cache location to the compiled value of caches.misc.dir Reduces duration of integration tests by: - Generating GoAT diagrams instead of Ditaa diagrams - Taking advantage of asciidoctor-diagram caching Closes #9202 Closes #10183 Closes #10473 Closes #14160
1 parent b037b93 commit b42c932

File tree

16 files changed

+1475
-202
lines changed

16 files changed

+1475
-202
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,12 @@ jobs:
4646
uses: ruby/setup-ruby@8aeb6ff8030dd539317f8e1769a044873b56ea71 # v1.268.0
4747
with:
4848
ruby-version: "3.4.5"
49-
- name: Install gems
49+
- name: Install Ruby gems
5050
run: |
5151
gem install asciidoctor -v "2.0.26"
5252
gem install asciidoctor-diagram -v "3.1.0"
53-
gem install asciidoctor-diagram-ditaamini -v "1.0.3"
5453
- name: Install GoAT
5554
run: go install github.com/blampe/goat/cmd/goat@177de93b192b8ffae608e5d9ec421cc99bf68402
56-
- name: Install Java # required by asciidoctor-diagram-ditaamini
57-
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
58-
with:
59-
distribution: temurin
60-
java-version: "25"
61-
java-package: jre
6255
- name: Install Python
6356
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
6457
with:

cache/filecache/filecache_config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,18 @@ const (
5151

5252
type Configs map[string]FileCacheConfig
5353

54+
// CacheDirModules returns the compiled path to the modules cache.
5455
// For internal use.
5556
func (c Configs) CacheDirModules() string {
5657
return c[CacheKeyModules].DirCompiled
5758
}
5859

60+
// CacheDirMisc returns the compiled path to the misc cache.
61+
// For internal use.
62+
func (c Configs) CacheDirMisc() string {
63+
return c[CacheKeyMisc].DirCompiled
64+
}
65+
5966
var defaultCacheConfigs = Configs{
6067
CacheKeyModules: {
6168
MaxAge: -1,

config/allconfig/configlanguage.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ func (c ConfigLanguage) WorkingDir() string {
135135
return c.m.Base.WorkingDir
136136
}
137137

138+
func (c ConfigLanguage) CacheDirMisc() string {
139+
return c.config.Caches.CacheDirMisc()
140+
}
141+
138142
func (c ConfigLanguage) Quiet() bool {
139143
return c.m.Base.Internal.Quiet
140144
}

config/configProvider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ type AllProvider interface {
7979
WorkingDir() string
8080
EnableEmoji() bool
8181
ConfiguredDimensions() *sitesmatrix.ConfiguredDimensions
82+
CacheDirMisc() string
8283
}
8384

8485
// We cannot import the media package as that would create a circular dependency.

htesting/test_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func IsGitHubAction() bool {
121121
}
122122

123123
// SupportsAll reports whether the running system supports all Hugo features,
124-
// e.g. Asciidoc, Pandoc etc.
124+
// e.g. AsciiDoc, Pandoc etc.
125125
func SupportsAll() bool {
126126
return IsGitHubAction() || os.Getenv("CI_LOCAL") != ""
127127
}

hugolib/page_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ func testAllMarkdownEnginesForPages(t *testing.T,
345345
shouldExecute func() bool
346346
}{
347347
{"md", func() bool { return true }},
348-
{"ad", func() bool { return asciidocext.Supports() }},
348+
{"ad", func() bool { ok, _ := asciidocext.Supports(); return ok }},
349349
{"rst", func() bool { return !htesting.IsRealCI() && rst.Supports() }},
350350
}
351351

@@ -574,7 +574,7 @@ func TestPageSummary(t *testing.T) {
574574
assertFunc := func(t *testing.T, ext string, pages page.Pages) {
575575
p := pages[0]
576576
checkPageTitle(t, p, "SimpleWithoutSummaryDelimiter")
577-
// Source is not Asciidoctor- or RST-compatible so don't test them
577+
// Source is not AsciiDoc- or RST-compatible so don't test them
578578
if ext != "ad" && ext != "rst" {
579579
checkPageContent(t, p, normalizeExpected(ext, "<p><a href=\"https://lipsum.com/\">Lorem ipsum</a> dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>\n\n<p>Additional text.</p>\n\n<p>Further text.</p>\n"), ext)
580580
checkPageSummary(t, p, normalizeExpected(ext, "<p><a href=\"https://lipsum.com/\">Lorem ipsum</a> dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p><p>Additional text.</p>"), ext)
@@ -604,7 +604,7 @@ func TestPageWithSummaryParameter(t *testing.T) {
604604
p := pages[0]
605605
checkPageTitle(t, p, "SimpleWithSummaryParameter")
606606
checkPageContent(t, p, normalizeExpected(ext, "<p>Some text.</p>\n\n<p>Some more text.</p>\n"), ext)
607-
// Summary is not Asciidoctor- or RST-compatible so don't test them
607+
// Summary is not AsciiDoc- or RST-compatible so don't test them
608608
if ext != "ad" && ext != "rst" {
609609
checkPageSummary(t, p, normalizeExpected(ext, "Page with summary parameter and <a href=\"http://www.example.com/\">a link</a>"), ext)
610610
}

hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ docs/p1/sub/mymixcasetext2.txt
132132
b.AssertFileContent("public/docs/p3/index.html", "<strong>Hello World Default</strong>")
133133
}
134134

135-
func TestPagesFromGoTmplAsciidocAndSimilar(t *testing.T) {
135+
func TestPagesFromGoTmplAsciiDocAndSimilar(t *testing.T) {
136136
files := `
137137
-- hugo.toml --
138138
disableKinds = ["taxonomy", "term", "rss", "sitemap"]
@@ -153,7 +153,7 @@ allow = ['asciidoctor', 'pandoc','rst2html', 'python']
153153

154154
b := hugolib.Test(t, files)
155155

156-
if asciidocext.Supports() {
156+
if ok, _ := asciidocext.Supports(); ok {
157157
b.AssertFileContent("public/docs/asciidoc/index.html",
158158
"Mark my words, <mark>automation is essential</mark>",
159159
"Path: /docs/asciidoc|",
@@ -503,7 +503,7 @@ baseURL = "https://example.com"
503503
func TestPagesFromGoTmplCascade(t *testing.T) {
504504
t.Parallel()
505505

506-
files := `
506+
files := `
507507
-- hugo.toml --
508508
disableKinds = ["taxonomy", "term", "rss", "sitemap"]
509509
baseURL = "https://example.com"
@@ -523,7 +523,7 @@ baseURL = "https://example.com"
523523
func TestPagesFromGoBuildOptions(t *testing.T) {
524524
t.Parallel()
525525

526-
files := `
526+
files := `
527527
-- hugo.toml --
528528
disableKinds = ["taxonomy", "term", "rss", "sitemap"]
529529
baseURL = "https://example.com"
@@ -644,11 +644,11 @@ func TestPagesFromGoTmplMenusMap(t *testing.T) {
644644
-- hugo.toml --
645645
disableKinds = ['rss','section','sitemap','taxonomy','term']
646646
-- content/_content.gotmpl --
647-
{{ $menu1 := dict
647+
{{ $menu1 := dict
648648
"parent" "main-page"
649649
"identifier" "id1"
650650
}}
651-
{{ $menu2 := dict
651+
{{ $menu2 := dict
652652
"parent" "main-page"
653653
"identifier" "id2"
654654
}}
@@ -859,7 +859,7 @@ Title: {{ .Title }}|Content: {{ .Content }}|
859859
func TestPagesFromGoTmplHome(t *testing.T) {
860860
t.Parallel()
861861

862-
files := `
862+
files := `
863863
-- hugo.toml --
864864
disableKinds = ["taxonomy", "term", "rss", "sitemap"]
865865
baseURL = "https://example.com"

hugolib/rebuild_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,9 +1927,9 @@ Myotherpartial Inline.|{{ .Title }}|
19271927
b.AssertFileContent("public/index.html", "My inline partial in all Edited.")
19281928
}
19291929

1930-
func TestRebuildEditAsciidocContentFile(t *testing.T) {
1931-
if !asciidocext.Supports() {
1932-
t.Skip("skip asciidoc")
1930+
func TestRebuildEditAsciiDocContentFile(t *testing.T) {
1931+
if ok, err := asciidocext.Supports(); !ok {
1932+
t.Skip(err)
19331933
}
19341934
files := `
19351935
-- hugo.toml --

hugolib/securitypolicies_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ baseURL = "https://example.org"
5454
Test(c, files)
5555
})
5656

57-
c.Run("Asciidoc, denied", func(c *qt.C) {
57+
c.Run("AsciiDoc, denied", func(c *qt.C) {
5858
c.Parallel()
59-
if !asciidocext.Supports() {
60-
c.Skip()
59+
if ok, err := asciidocext.Supports(); !ok {
60+
c.Skip(err)
6161
}
6262

6363
files := `

0 commit comments

Comments
 (0)