Skip to content

Commit d04e10f

Browse files
committed
docs: install page releases extension
1 parent 0d52577 commit d04e10f

File tree

5 files changed

+79
-5
lines changed

5 files changed

+79
-5
lines changed

docs/antora-playbook.yml

+1
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,5 @@ asciidoc:
8383
extensions:
8484
- '@asciidoctor/tabs'
8585
- ./extensions/mrdocs-demos.js
86+
- ./extensions/mrdocs-releases.js
8687

docs/extensions/mrdocs-releases.js

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
Copyright (c) 2024 Alan de Freitas ([email protected])
3+
4+
Distributed under the Boost Software License, Version 1.0. (See accompanying
5+
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
7+
Official repository: https://github.com/cppalliance/mrdocs
8+
*/
9+
10+
const https = require('https');
11+
const request = require('sync-request');
12+
const fs = require("fs");
13+
14+
function humanizeBytes(bytes) {
15+
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
16+
if (bytes == 0) return '0 Byte';
17+
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
18+
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
19+
}
20+
21+
function humanizeDate(date) {
22+
const options = { year: 'numeric', month: 'long', day: 'numeric' };
23+
return new Date(date).toLocaleDateString('en-US', options);
24+
}
25+
26+
module.exports = function (registry) {
27+
registry.blockMacro('mrdocs-releases', function () {
28+
const self = this
29+
self.process(function (parent, target, attrs) {
30+
// Collect all release URLs
31+
let cacheFilenamePath = 'releasesResponse.json';
32+
let cachePath = `${__dirname}/../build/requests/${cacheFilenamePath}`;
33+
fs.mkdirSync(`${__dirname}/../build/requests/`, { recursive: true });
34+
const readFromCacheFile = fs.existsSync(cachePath) && fs.statSync(cachePath).mtime > new Date(Date.now() - 1000 * 60 * 60 * 24);
35+
const releasesResponse =
36+
readFromCacheFile ?
37+
fs.readFileSync(cachePath, 'utf-8') :
38+
request('GET', 'https://api.github.com/repos/cppalliance/mrdocs/releases', {
39+
headers: {
40+
'User-Agent': 'request'
41+
}
42+
}).getBody('utf-8')
43+
if (!readFromCacheFile) {
44+
fs.writeFileSync(cachePath, releasesResponse);
45+
}
46+
const releases = JSON.parse(releasesResponse)
47+
48+
// Create table
49+
let text = '|===\n'
50+
text += '| 3+| 🪟 Windows 2+| 🐧 Linux \n'
51+
text += '| 📃 Release | 📦 7z | 📦 msi | 📦 zip | 📦 tar.xz | 📦 tar.gz \n'
52+
for (const release of releases) {
53+
if (release.name === 'llvm-package') continue
54+
text += `| ${release.html_url}[${release.name},window=_blank]\n\n${humanizeDate(release.published_at)} `
55+
const assetSuffixes = ['win64.7z', 'win64.msi', 'win64.zip', 'Linux.tar.xz', 'Linux.tar.gz']
56+
for (const suffix of assetSuffixes) {
57+
const asset = release.assets.find(asset => asset.name.endsWith(suffix))
58+
if (asset) {
59+
text += `| ${asset.browser_download_url}[🔗 ${asset.name}]\n\n(${humanizeBytes(asset.size)}) `
60+
} else {
61+
text += '| - '
62+
}
63+
}
64+
text += '\n'
65+
}
66+
text += '|===\n'
67+
return self.parseContent(parent, text)
68+
})
69+
})
70+
}

docs/local-antora-playbook.yml

+1
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,5 @@ asciidoc:
8080
extensions:
8181
- '@asciidoctor/tabs'
8282
- ./extensions/mrdocs-demos.js
83+
- ./extensions/mrdocs-releases.js
8384

docs/modules/ROOT/nav.adoc

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
* xref:index.adoc[]
22
* xref:demos.adoc[]
3-
* xref:install.adoc[]
4-
* xref:usage.adoc[]
3+
* xref:install.adoc[Installation]
4+
* xref:usage.adoc[Getting Started]
5+
* xref:commands.adoc[Documenting the Code]
56
* xref:config-file.adoc[]
6-
* xref:commands.adoc[]
77
* xref:design-notes.adoc[]
88
* xref:contribute.adoc[]
99
* xref:license.adoc[]

docs/modules/ROOT/pages/install.adoc

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
= Install
22

33
[#mrdocs-binaries]
4-
== Binaries
4+
== Binary Packages
55

66
Binary packages are available from our https://github.com/cppalliance/mrdocs/releases[Release Page,window="_blank"].
77
Most users should use these packages.
88
9+
mrdocs-releases::[]
10+
911
[#mrdocs-source]
10-
== Source
12+
== Install from Source
1113
1214
The following instructions assume we are at a parent directory that's going to contain both the MrDocs and the third-party dependencies directories.
1315

0 commit comments

Comments
 (0)