Skip to content

Commit

Permalink
initial setup
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed Sep 11, 2023
1 parent 90d7e41 commit 293cd27
Show file tree
Hide file tree
Showing 12 changed files with 6,779 additions and 545 deletions.
42 changes: 42 additions & 0 deletions components/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// eslint-disable-next-line no-unused-vars
import { AsyncAPIDocumentInterface } from '@asyncapi/parser';
import { includeFile, generateBase64Favicon, renderSpec, stringifySpec, stringifyConfiguration } from '../helpers/all';

/**
* @param {{asyncapi: AsyncAPIDocumentInterface, params: any}} param0
*/
export function Index({ asyncapi, params }) {
return (`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
${params.baseHref && `<base href="${params.baseHref}">`}
<title>${asyncapi.info().title()} ${asyncapi.info().version()} documentation</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/x-icon" href="${generateBase64Favicon(params)}" />
${params.singleFile && `<style type="text/css">
${includeFile("template/css/global.min.css")}
${includeFile("template/css/asyncapi.min.css")}
</style>`}
${!params.singleFile && `<link href="css/global.min.css" rel="stylesheet">
<link href="css/asyncapi.min.css" rel="stylesheet">`}
</head>
<body>
<div id="root">${renderSpec(asyncapi, params)}</div>
${params.singleFile && ` <script type="text/javascript">
{{ "template/js/asyncapi-ui.min.js" | includeFile | safe }}
</script>`}
${!params.singleFile && `<script src="js/asyncapi-ui.min.js" type="application/javascript"></script>`}
<script>
const schema = ${stringifySpec(asyncapi)};
const config = ${stringifyConfiguration(params)};
AsyncApiStandalone.hydrate({ schema, config }, document.getElementById("root"));
</script>
</body>
</html>`
);
}

16 changes: 6 additions & 10 deletions filters/all.js → helpers/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const React = require('react');
const ReactDOMServer = require('react-dom/server');
const fetch = require('node-fetch');
const { default: AsyncApiComponent, hljs } = require('@asyncapi/react-component');
const { AsyncAPIDocument } = require('@asyncapi/parser');
const { stringify } = require('@asyncapi/parser');

const filter = module.exports;

Expand Down Expand Up @@ -96,32 +96,28 @@ filter.loadLanguagesConfig = loadLanguagesConfig;
/**
* Generate Base64 value from favicon
*/
async function generateBase64Favicon(params, callback) {
async function generateBase64Favicon(params) {
const favicon = params.favicon;

// generate Base64 of AsyncAPI logo
if (!favicon) {
const data = "data:image/x-icon;base64," + fs.readFileSync(path.resolve(__dirname, '../assets/asyncapi-favicon.ico'), "base64");
return callback(null, data);
return "data:image/x-icon;base64," + fs.readFileSync(path.resolve(__dirname, '../assets/asyncapi-favicon.ico'), "base64");
}

try {
// Attempt to fetch favicon
const response = await fetch(favicon);
if (response.status == 200) {
const buffer = await response.buffer()
const data = "data:image/x-icon;base64," + buffer.toString('base64');
callback(null, data);
return "data:image/x-icon;base64," + buffer.toString('base64');
}
} catch (fetchErr) {
// Failed to fetch favicon...
try {
// Attempt to read favicon as file
const data = "data:image/x-icon;base64," + fs.readFileSync(favicon, "base64");
callback(null, data);
return "data:image/x-icon;base64," + fs.readFileSync(favicon, "base64");
} catch (err) {
console.error("Failed to fetch/read favicon", fetchErr, err);
callback(err);
throw err;
}
}
Expand All @@ -143,7 +139,7 @@ filter.includeFile = includeFile;
* and annotates that specification is parsed.
*/
function stringifySpec(asyncapi) {
return AsyncAPIDocument.stringify(asyncapi);
return stringify(asyncapi);
}
filter.stringifySpec = stringifySpec;

Expand Down
16 changes: 0 additions & 16 deletions hooks/02_renameOutFile.js

This file was deleted.

Loading

0 comments on commit 293cd27

Please sign in to comment.