Skip to content

Commit 81be0b1

Browse files
authored
feat: PDF download button (#9351)
1 parent 6b04165 commit 81be0b1

File tree

91 files changed

+205
-90
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+205
-90
lines changed

docs/docfx.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"_appTitle": "docfx",
3333
"_appName": "docfx",
3434
"_appFooter": "<span>Supported by the <a href=\"https://dotnetfoundation.org\">.NET Foundation</a>. Made with <a href=\"https://dotnet.github.io/docfx\">docfx</a></span>",
35-
"_googleAnalyticsTagId": "G-Q5N6XJHEX5"
35+
"_googleAnalyticsTagId": "G-Q5N6XJHEX5",
36+
"pdf": true
3637
},
3738
"markdownEngineProperties": {
3839
"alerts": {

templates/default(zh-cn)/token.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@
5858
"themeDark": "夜晚",
5959
"themeAuto": "自动",
6060
"changeTheme": "切换主题",
61-
"copy": "复制"
61+
"copy": "复制",
62+
"downloadPdf": "下载 PDF"
6263
}

templates/default/token.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,6 @@
6868
"themeDark": "Dark",
6969
"themeAuto": "Auto",
7070
"changeTheme": "Change theme",
71-
"copy": "Copy"
71+
"copy": "Copy",
72+
"downloadPdf": "Download PDF"
7273
}

templates/modern/layout/_master.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<meta name="loc:themeAuto" content="{{__global.themeAuto}}">
3636
<meta name="loc:changeTheme" content="{{__global.changeTheme}}">
3737
<meta name="loc:copy" content="{{__global.copy}}">
38+
<meta name="loc:downloadPdf" content="{{__global.downloadPdf}}">
3839
{{/redirect_url}}
3940
</head>
4041

@@ -135,7 +136,7 @@
135136
<div class="container-xxl search-results" id="search-results"></div>
136137
{{/_enableSearch}}
137138

138-
<footer class="border-top">
139+
<footer class="border-top text-secondary">
139140
<div class="container-xxl">
140141
<div class="flex-fill">
141142
{{{_appFooter}}}{{^_appFooter}}<span>Made with <a href="https://dotnet.github.io/docfx">docfx</a></span>{{/_appFooter}}

templates/modern/src/layout.scss

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
$header-height: 60px;
77
$footer-height: 60px;
88
$main-padding-top: 1.6rem;
9-
$main-padding-bottom: 4rem;
9+
$main-padding-bottom: 2rem;
1010

1111
// Makes a div sticky to top
1212
@mixin sticky-top {
@@ -53,6 +53,7 @@ body[data-layout="landing"] {
5353
}
5454

5555
>footer {
56+
font-size: 14px;
5657
padding: 1rem 0;
5758
height: $footer-height;
5859

@@ -121,8 +122,7 @@ body[data-layout="landing"] {
121122
>.toc-offcanvas {
122123
flex: .35;
123124
display: block;
124-
overflow-x: hidden;
125-
overflow-y: auto;
125+
overflow: hidden;
126126
max-width: 360px;
127127
max-height: calc(100vh - $header-height - $main-padding-top);
128128

@@ -131,9 +131,15 @@ body[data-layout="landing"] {
131131
@include media-breakpoint-down(md) {
132132
flex: 0;
133133
}
134+
135+
.offcanvas-start, .offcanvas-body {
136+
height: 100%;
137+
}
134138
}
135139

136140
>.content {
141+
display: flex;
142+
flex-direction: column;
137143
flex: 1;
138144
min-width: 0;
139145
margin: 0 3rem;
@@ -146,6 +152,10 @@ body[data-layout="landing"] {
146152
min-height: 40px;
147153
}
148154

155+
article {
156+
flex: 1;
157+
}
158+
149159
>.contribution,
150160
>.next-article {
151161
display: flex;

templates/modern/src/toc.scss

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ $expand-stub-width: .85rem;
88
.toc {
99
min-width: 0;
1010
width: 100%;
11+
height: 100%;
12+
display: flex;
13+
flex-direction: column;
1114

1215
ul {
1316
font-size: 14px;
@@ -72,7 +75,7 @@ $expand-stub-width: .85rem;
7275
display: flex;
7376
position: relative;
7477
align-items: center;
75-
margin-bottom: 1rem;
78+
margin-bottom: .5rem;
7679

7780
>i.bi {
7881
position: absolute;
@@ -89,4 +92,15 @@ $expand-stub-width: .85rem;
8992
font-size: .9em;
9093
color: $secondary;
9194
}
95+
96+
a.pdf-link {
97+
@include underline-on-hover;
98+
99+
&::before {
100+
content: "\F756";
101+
display: inline-block;
102+
103+
@include adjust-icon;
104+
}
105+
}
92106
}

templates/modern/src/toc.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export async function renderToc(): Promise<TocNode[]> {
2424
const disableTocFilter = meta('docfx:disabletocfilter') === 'true'
2525

2626
const tocUrl = new URL(tocrel.replace(/.html$/gi, '.json'), window.location.href)
27-
const { items } = await (await fetch(tocUrl)).json()
27+
const { items, pdf, pdfFileName } = await (await fetch(tocUrl)).json()
2828

2929
const tocFilterUrl = disableTocFilter ? '' : (localStorage?.getItem('tocFilterUrl') || '')
3030
let tocFilter = disableTocFilter ? '' : (localStorage?.getItem('tocFilter') || '')
@@ -92,7 +92,10 @@ export async function renderToc(): Promise<TocNode[]> {
9292
}
9393

9494
function renderToc() {
95-
render(html`${renderTocFilter()} ${renderTocNodes(items) || renderNoFilterResult()}`, tocContainer)
95+
render(html`
96+
${renderTocFilter()}
97+
<div class="flex-fill overflow-y-auto">${renderTocNodes(items) || renderNoFilterResult()}</div>
98+
${renderDownloadPdf()}`, tocContainer)
9699
}
97100

98101
function renderTocNodes(nodes: TocNode[]): TemplateResult {
@@ -150,6 +153,10 @@ export async function renderToc(): Promise<TocNode[]> {
150153
return tocFilter === '' ? null : html`<div class='no-result'>${loc('searchNoResults', { query: tocFilter })}</div>`
151154
}
152155

156+
function renderDownloadPdf(): TemplateResult {
157+
return pdf ? html`<div class="py-2 mb-md-4"><a class="pdf-link" href="${pdfFileName || 'toc.pdf'}">${loc('downloadPdf')}</a></div>` : null
158+
}
159+
153160
function normalizeUrlPath(url: { pathname: string }): string {
154161
return url.pathname.replace(/\/index\.html$/gi, '/')
155162
}

test/docfx.Snapshot.Tests/SamplesTest.CSharp/api/CSharp10.ConstantInterpolatedStrings.html.view.verified.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,7 @@
10791079
"themeAuto": "Auto",
10801080
"changeTheme": "Change theme",
10811081
"copy": "Copy",
1082+
"downloadPdf": "Download PDF",
10821083
"_shared": {}
10831084
},
10841085
"yamlmime": "ManagedReference",

test/docfx.Snapshot.Tests/SamplesTest.CSharp/api/CSharp10.Issue7737.html.view.verified.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@
809809
"themeAuto": "Auto",
810810
"changeTheme": "Change theme",
811811
"copy": "Copy",
812+
"downloadPdf": "Download PDF",
812813
"_shared": {}
813814
},
814815
"yamlmime": "ManagedReference",

test/docfx.Snapshot.Tests/SamplesTest.CSharp/api/CSharp10.ParameterlessStructConstructors.html.view.verified.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,7 @@
12141214
"themeAuto": "Auto",
12151215
"changeTheme": "Change theme",
12161216
"copy": "Copy",
1217+
"downloadPdf": "Download PDF",
12171218
"_shared": {}
12181219
},
12191220
"yamlmime": "ManagedReference",

0 commit comments

Comments
 (0)