Skip to content

Commit d2e6d81

Browse files
committed
Use render-link hook to resolve references in specs
1 parent e61624c commit d2e6d81

File tree

3 files changed

+32
-96
lines changed

3 files changed

+32
-96
lines changed

content/en/docs/specs/status.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ same as the **Protocol** status.
5959
- [Specification][tracing]
6060
- {{% spec_status "API" "otel/trace/api" "Status" %}}
6161
- {{% spec_status "SDK" "otel/trace/sdk" "Status" %}}
62-
- {{% spec_status "Protocol" "otlp" "/document-status/.*for.*trace" %}}
62+
- {{% spec_status "Protocol" "otlp" "/document-status.*for.*trace" %}}
6363
- Notes:
6464
- The tracing specification is now completely stable, and covered by long term
6565
support.
@@ -73,7 +73,7 @@ same as the **Protocol** status.
7373
- [Specification][metrics]
7474
- {{% spec_status "API" "otel/metrics/api" "Status" %}}
7575
- {{% spec_status "SDK" "otel/metrics/sdk" "Status" %}}
76-
- {{% spec_status "Protocol" "otlp" "/document-status/.*for.*metric" %}}
76+
- {{% spec_status "Protocol" "otlp" "/document-status.*for.*metric" %}}
7777
- Notes:
7878
- OpenTelemetry Metrics is currently under active development.
7979
- The data model is stable and released as part of the OTLP protocol.
@@ -98,7 +98,7 @@ same as the **Protocol** status.
9898
- [Specification][logging]
9999
- {{% spec_status "Bridge API" "otel/logs/api" "Status" %}}
100100
- {{% spec_status "SDK" "otel/logs/sdk" "Status" %}}
101-
- {{% spec_status "Protocol" "otlp" "/document-status/.*for.*log" %}}
101+
- {{% spec_status "Protocol" "otlp" "/document-status.*for.*log" %}}
102102
- Notes:
103103
- The [logs data model][] is released as part of the OpenTelemetry Protocol.
104104
- Log processing for many data formats has been added to the Collector, thanks
@@ -116,7 +116,7 @@ same as the **Protocol** status.
116116
### Profiles
117117

118118
- [Specification][profiles]
119-
- {{% spec_status "Protocol" "otlp" "/document-status/.*for.*profiles" %}}
119+
- {{% spec_status "Protocol" "otlp" "/document-status.*for.*profiles" %}}
120120

121121
[baggage]: /docs/specs/otel/baggage/
122122
[event semantic conventions]: /docs/specs/semconv/general/events/

layouts/_default/_markup/render-link.html

+26-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{{ $url := .Destination -}}
1+
{{ $url := .Destination -}} {{/* TODO: rename to $dest */ -}}
2+
{{ $u := urls.Parse $url -}}
23

34
{{/*
45

@@ -10,9 +11,32 @@
1011
- $url is an absolute path -- that is, it starts with /
1112
- The $url target page exists in this locale
1213

14+
Reference to Hugo's default:
15+
https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/_default/_markup/render-link.html
16+
1317
*/ -}}
1418

15-
{{ if hasPrefix $url "/" -}}
19+
20+
{{ if and
21+
(strings.HasPrefix $.PageInner.RelPermalink "/docs/specs")
22+
(not $u.IsAbs)
23+
(not (strings.HasPrefix $url "#"))
24+
-}}
25+
{{ $path := replaceRE `\bREADME\.md\b` "_index.md" $u.Path -}}
26+
{{ $href := $url -}}
27+
{{ with or
28+
($.PageInner.GetPage $path)
29+
($.PageInner.Resources.Get $path)
30+
(resources.Get $path)
31+
-}}
32+
{{ $href = .RelPermalink -}}
33+
{{ with $u.RawQuery -}}{{ $href = printf "%s?%s" $href . -}}{{ end -}}
34+
{{ with $u.Fragment -}}{{ $href = printf "%s#%s" $href . -}}{{ end -}}
35+
{{ else -}}
36+
{{ warnf "File %s: cannot resolve spec link reference '%s'" .Page.File.Filename $url -}}
37+
{{ end -}}
38+
{{ $url = $href -}}
39+
{{ else if hasPrefix $url "/" -}}
1640
{{/* Hard-coded default lang since it's what's most efficient and won't change :) */ -}}
1741
{{ $defaultLang := "en" -}}
1842
{{ $lang := .Page.Language.Lang -}}
@@ -22,7 +46,6 @@
2246
{{ warnf "File %s: drop unnecessary '%s' prefix from %s"
2347
.Page.File.Filename $langPathPrefix $url -}}
2448
{{ else -}}
25-
{{ $u := urls.Parse $url -}}
2649
{{ $localizedPagePath := add $langPathPrefix (strings.TrimPrefix "/" $url) -}}
2750
{{/*
2851
Look for the page (referenced by $url) in this page's locale's site.

scripts/content-modules/adjust-pages.pl

+2-89
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
my $otlpSpecVers = $versions{'otlp:'};
2727
my $semconvVers = $versions{'semconv:'};
2828
my %patchMsgCount;
29-
my $openRelref = '{{% relref';
3029

3130
sub printTitleAndFrontMatter() {
3231
print "---\n";
@@ -119,7 +118,7 @@ ($$)
119118

120119
## Semconv
121120

122-
if ($ARGV =~ /\/semconv/) {
121+
if ($ARGV =~ /^tmp\/semconv/) {
123122
my $otel_spec_event_deprecation = '(opentelemetry-specification/blob/main/specification/logs)/event-(api|sdk).md';
124123
if (/$otel_spec_event_deprecation/) {
125124
# Cf. https://github.com/open-telemetry/opentelemetry-specification/pull/4359
@@ -131,13 +130,6 @@ ($$)
131130
s|(\]:\s*)/docs/|$1$specBasePath/semconv/|;
132131

133132
s|\((/model/.*?)\)|($semconvSpecRepoUrl/tree/v$semconvVers/$1)|g;
134-
135-
# TODO: drop after fix of https://github.com/open-telemetry/semantic-conventions/pull/1316
136-
s|#instrument-advice\b|#instrument-advisory-parameters|g;
137-
138-
# TODO: drop after fix of https://github.com/open-telemetry/semantic-conventions/issues/1313
139-
s|(/database/database-spans\.md)#batch-operations|$1|g;
140-
s|(/messaging/messaging-spans\.md)#common-messaging-operations|$1|g;
141133
}
142134

143135

@@ -153,7 +145,6 @@ ($$)
153145

154146
s|\(https://github.com/open-telemetry/opentelemetry-specification\)|($specBasePath/otel/)|;
155147
s|(\]\()/specification/|$1$specBasePath/otel/)|;
156-
s|\.\./semantic_conventions/README.md|$semConvRef| if $ARGV =~ /overview/;
157148
s|\.\./specification/(.*?\))|../otel/$1|g if $ARGV =~ /otel\/specification/;
158149

159150
# Match markdown inline links or link definitions to OTel spec pages: "[...](URL)" or "[...]: URL"
@@ -172,93 +163,15 @@ ($$)
172163
s|(\]\()([^)]+\.png\))|$1../$2|g if $ARGV =~ /\btmp\/semconv\/docs\/general\/attributes/;
173164
s|(\]\()([^)]+\.png\))|$1../$2|g if $ARGV =~ /\btmp\/semconv\/docs\/http\/http-spans/;
174165

175-
# Handle links containing `README.md`
176-
177166
# Rewrite paths that are outside of the spec folders as external links:
178-
179167
s|\.\.\/README.md|$otelSpecRepoUrl/|g if $ARGV =~ /specification._index/;
180-
s|\.\.\/README.md|..| if $ARGV =~ /specification\/library-guidelines.md/;
168+
s|\.\.\/README.md|/docs/specs/otel/| if $ARGV =~ /specification\/library-guidelines.md/;
181169

182170
s|(\.\.\/)+(experimental\/[^)]+)|$otelSpecRepoUrl/tree/v$otelSpecVers/$2|g;
183171
s|(\.\.\/)+(supplementary-guidelines\/compatibility\/[^)]+)|$otelSpecRepoUrl/tree/v$otelSpecVers/$2|g;
184172

185173
s|\.\./((?:examples/)?README\.md)|$otlpSpecRepoUrl/tree/v$otlpSpecVers/$1|g if $ARGV =~ /^tmp\/otlp/;
186174

187-
# Replace `README.md` by `_index.md` in markdown links:
188-
s{
189-
# An inline markdown link, just before the URL: `](` like in `[docs](/docs)`
190-
(
191-
\]\(
192-
)
193-
194-
# Match any local path. In the `[^...]` exclude group we have:
195-
# - `:` so as to exclude external links, which use `:` after a protocol specifier
196-
# - `)` prevents us from gobbling up past the end of the inline link
197-
198-
([^:\)]*)
199-
README\.md
200-
([^)]*) # Any anchor specifier
201-
(\)) # The end of the inline link
202-
}{$1$openRelref "$2_index.md$3" \%\}\}$4}gx;
203-
204-
# Replace `README.md` by `_index.md` in markdown link definitions:
205-
s{
206-
# A markdown link definition, just before the URL: `]:`, like in `[docs]: /docs`
207-
(
208-
\]:\s*
209-
)
210-
211-
# Match any local path. In the `[^...]` exclude group we have:
212-
# - `:` so as to exclude external links, which use `:` after a protocol specifier
213-
# - A space should prevent us from gobbling up beyond the end of a link def
214-
215-
([^: ]*)
216-
README\.md
217-
([^)]*) # Any anchor specifier
218-
(\n)$ # End of the link definition
219-
}{$1$openRelref "$2_index.md$3" \%\}\}$4}gx;
220-
221-
# Rewrite inline links
222-
if ($ARGV =~ /\btmp\/opamp/) {
223-
s|\]\(([^:\)]*?)\.md((#.*?)?)\)|]($1/$2)|g;
224-
} else {
225-
# Generally rewrite markdown links as {{% relref "..." %}} expressions,
226-
# since that gets Hugo to resolve the links. We can't use the raw path since
227-
# some need a `../` prefix to resolve. We let Hugo handle that.
228-
s{
229-
# Match markdown link `](` just before the URL
230-
(\]\()
231-
232-
# Match the link path:
233-
(
234-
# Match paths upto but excluding `.md`. The character exclusions are as follows:
235-
#
236-
# - `:` ensures the URL is a path, not an external link, which has a protocol followe by `:`
237-
# - `)` so we don't overrun the end of the markdown link, which ends with `)`
238-
# - `{` or `}` so that the path doesn't contain Hugo {{...}}
239-
240-
[^:\)\{\}]*?
241-
242-
\.md
243-
244-
# Match optional anchor of the form `#some-id`
245-
(?:
246-
\#.*?
247-
)?
248-
)
249-
# Closing parenthesis of markdown link
250-
\)
251-
}{$1$openRelref "$2" \%\}\}\)}gx;
252-
}
253-
254-
# Rewrite link defs to local pages such as the following:
255-
#
256-
# [specification]: overview.md
257-
# [faas]: some-path/faas-spans.md (FaaS trace conventions)
258-
#
259-
# The subregex `[:\s]+` excludes external URLs (because they contain a colon after the protocol)
260-
s|^(\[[^\]]+\]:\s*)([^:\s]+)(\s*(\(.*\))?)$|$1\{{% relref "$2" %}}$3|g;
261-
262175
# Make website-local page references local:
263176
s|https://opentelemetry.io/|/|g;
264177

0 commit comments

Comments
 (0)