Skip to content

Commit

Permalink
feat: Add singleFile param to generate everything in one index.html (#62
Browse files Browse the repository at this point in the history
)
  • Loading branch information
GordeevArt authored Sep 11, 2020
1 parent c795802 commit d891c5d
Show file tree
Hide file tree
Showing 7 changed files with 2,038 additions and 2,388 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/welcome-first-time-contrib.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Welcome first time contributors

on:
pull_request:
pull_request_target:
types:
- opened
issues:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ npm install -g @asyncapi/generator
|---|---|---|---|---|
|sidebarOrganization|Defines how the sidebar should be organized. Set its value to `byTagsNoRoot` to categorize operations by operations tags. Set its value to `byTags` when you have tags on a root level. These tags are used to model tags navigation and need to have the same tags in operations.|No|`byTags`, `byTagsNoRoot`|`byTagsNoRoot`|
|baseHref|Sets the base URL for links and forms.|No|*Any*|`/docs`|
|singleFile|Set output into one html-file with styles and scripts inside|No|`true`,`false`|`true`|

## Development

Expand Down
25 changes: 25 additions & 0 deletions hooks/01_removeNotRelevantParts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const fs = require('fs');
const path = require('path');

module.exports = {
'generate:after': generator => {

const params = generator.templateParams;
const singleFile = params.singleFile === 'true';

if (singleFile) {

const jsDir = path.resolve(generator.targetDir, 'js');
const cssDir = path.resolve(generator.targetDir, 'css');

const callback = (error) => {
if (error) {
throw error;
}
};

fs.rmdir(jsDir, {recursive: true}, callback);
fs.rmdir(cssDir, {recursive: true}, callback);
}
}
};
4,327 changes: 1,943 additions & 2,384 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
"baseHref": {
"description": "Sets the base URL for links and forms.",
"required": false
},
"singleFile": {
"description": "If set this parameter to true generate single html file with scripts and styles inside",
"required": false,
"default": false
}
},
"generator": ">=0.50.0 <2.0.0",
Expand Down
19 changes: 19 additions & 0 deletions template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,21 @@
{% endif %}
<title>{{asyncapi.info().title()}} {{asyncapi.info().version()}} documentation</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{% if params.singleFile %}
<style type="text/css">
{% include "template/css/tailwind.min.css" %}
</style>
<style type="text/css">
{% include "template/css/atom-one-dark.min.css" %}
</style>
<style type="text/css">
{% include "template/css/main.css" %}
</style>
{% else %}
<link href="css/tailwind.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/atom-one-dark.min.css" />
<link rel="stylesheet" href="css/main.css" />
{% endif %}
</head>
<body>
<div class="relative md:flex lg:flex xl:flex">
Expand All @@ -19,7 +31,14 @@
</div>
<div class="examples-panel absolute pin-t pin-r pin-b"></div>
</div>
{% if params.singleFile %}
<script type="text/javascript">
{% include "template/js/highlight.min.js" %}
{% include "template/js/main.js" %}
</script>
{% else %}
<script src="js/highlight.min.js" type="application/javascript"></script>
<script src="js/main.js" type="application/javascript"></script>
{% endif %}
</body>
</html>
47 changes: 44 additions & 3 deletions template/js/highlight.min.js

Large diffs are not rendered by default.

0 comments on commit d891c5d

Please sign in to comment.