Skip to content

Commit

Permalink
docs: install page releases extension
Browse files Browse the repository at this point in the history
  • Loading branch information
alandefreitas committed Jun 11, 2024
1 parent 0d52577 commit d04e10f
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/antora-playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,5 @@ asciidoc:
extensions:
- '@asciidoctor/tabs'
- ./extensions/mrdocs-demos.js
- ./extensions/mrdocs-releases.js

70 changes: 70 additions & 0 deletions docs/extensions/mrdocs-releases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
Copyright (c) 2024 Alan de Freitas ([email protected])
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Official repository: https://github.com/cppalliance/mrdocs
*/

const https = require('https');
const request = require('sync-request');
const fs = require("fs");

function humanizeBytes(bytes) {
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return '0 Byte';
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
}

function humanizeDate(date) {
const options = { year: 'numeric', month: 'long', day: 'numeric' };
return new Date(date).toLocaleDateString('en-US', options);
}

module.exports = function (registry) {
registry.blockMacro('mrdocs-releases', function () {
const self = this
self.process(function (parent, target, attrs) {
// Collect all release URLs
let cacheFilenamePath = 'releasesResponse.json';
let cachePath = `${__dirname}/../build/requests/${cacheFilenamePath}`;
fs.mkdirSync(`${__dirname}/../build/requests/`, { recursive: true });
const readFromCacheFile = fs.existsSync(cachePath) && fs.statSync(cachePath).mtime > new Date(Date.now() - 1000 * 60 * 60 * 24);
const releasesResponse =
readFromCacheFile ?
fs.readFileSync(cachePath, 'utf-8') :
request('GET', 'https://api.github.com/repos/cppalliance/mrdocs/releases', {
headers: {
'User-Agent': 'request'
}
}).getBody('utf-8')
if (!readFromCacheFile) {
fs.writeFileSync(cachePath, releasesResponse);
}
const releases = JSON.parse(releasesResponse)

// Create table
let text = '|===\n'
text += '| 3+| 🪟 Windows 2+| 🐧 Linux \n'
text += '| 📃 Release | 📦 7z | 📦 msi | 📦 zip | 📦 tar.xz | 📦 tar.gz \n'
for (const release of releases) {
if (release.name === 'llvm-package') continue
text += `| ${release.html_url}[${release.name},window=_blank]\n\n${humanizeDate(release.published_at)} `
const assetSuffixes = ['win64.7z', 'win64.msi', 'win64.zip', 'Linux.tar.xz', 'Linux.tar.gz']
for (const suffix of assetSuffixes) {
const asset = release.assets.find(asset => asset.name.endsWith(suffix))
if (asset) {
text += `| ${asset.browser_download_url}[🔗 ${asset.name}]\n\n(${humanizeBytes(asset.size)}) `
} else {
text += '| - '
}
}
text += '\n'
}
text += '|===\n'
return self.parseContent(parent, text)
})
})
}
1 change: 1 addition & 0 deletions docs/local-antora-playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,5 @@ asciidoc:
extensions:
- '@asciidoctor/tabs'
- ./extensions/mrdocs-demos.js
- ./extensions/mrdocs-releases.js

6 changes: 3 additions & 3 deletions docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
* xref:index.adoc[]
* xref:demos.adoc[]
* xref:install.adoc[]
* xref:usage.adoc[]
* xref:install.adoc[Installation]
* xref:usage.adoc[Getting Started]
* xref:commands.adoc[Documenting the Code]
* xref:config-file.adoc[]
* xref:commands.adoc[]
* xref:design-notes.adoc[]
* xref:contribute.adoc[]
* xref:license.adoc[]
6 changes: 4 additions & 2 deletions docs/modules/ROOT/pages/install.adoc
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
= Install

[#mrdocs-binaries]
== Binaries
== Binary Packages

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

0 comments on commit d04e10f

Please sign in to comment.