Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDOC-619 #122

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions createHtmlTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs');

(async () => {
const scriptText = fs.readFileSync('build/static/js/export-main.js');
const cssText = fs.readFileSync('build/static/css/export-main.css');

fs.writeFile(
'build/index-template.html',
`<!DOCTYPE html>
<html lang="en">
<head>
<base href=".">
<meta charset="utf-8"/>
<link rel="icon" href="https://editor.jsight.io/favicon.png'}"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="theme-color" content="#000000"/>
<meta name="description" content="Welcome to JSight"/>
<link rel="apple-touch-icon-precomposed" sizes="512x512" href="https://editor.jsight.io/apple-touch-icon-512x512.png" />
<link rel="apple-touch-icon-precomposed" sizes="180x180" href="https://editor.jsight.io/apple-touch-icon-152x152.png" />
<meta name="application-name" content="&nbsp;"/>
<meta name="msapplication-TileColor" content="#FFFFFF"/>
<meta name="msapplication-TileImage" content="https://editor.jsight.io/mstile-144x144.png"/>

<meta property="og:title" content="JSight — the Best API documentation language and tool"/>
<meta property="og:description" content="Are you fed up of OpenAPI? JSight is the simplest, user-friendly, compact language for description of REST API. Feel the difference compared to Swagger!"/>
<meta property="og:type" content="website"/>
<meta property="og:url" content="https://editor.jsight.io"/>
<meta property="og:image" content="https://editor.jsight.io/oggImage.png"/>
<meta property="og:image:type" content="image/png">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="720">
<meta property="og:site_name" content="JSight.io">
<meta property="fb:app_id" content="609425093466922">

<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@jsightapi">
<meta name="twitter:creator" content="@jsightapi">
<link rel="manifest" href="https://editor.jsight.io/manifest.json" />
<title>JSight Online Editor</title>
<script>
window.isExport = true;
var jdoc = {{ jdoc }}
</script>
<script type="module">
${scriptText}
</script>
${cssText ? `<style>${cssText}</style>` : ''}
</head>
<body>
<div id="root"></div>
</body>
</html>`,
function (err) {
if (err) throw err;
console.log('File is created successfully.');
}
);
})();
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"start": "react-app-rewired start",
"one": "./scripts/save-export-js.sh",
"build-export": "prettier --write ./src && GENERATE_SOURCEMAP=false REACT_VIEW_TYPE=doc react-app-rewired build && ./scripts/save-export-js.sh",
"build": "GENERATE_SOURCEMAP=false react-app-rewired build && ./scripts/return-export-js.sh",
"build": "GENERATE_SOURCEMAP=false react-app-rewired build && ./scripts/return-export-js.sh && node createHtmlTemplate.js",
"test": "react-app-rewired test",
"eject": "react-scripts eject"
},
Expand Down
114 changes: 29 additions & 85 deletions src/assets/fonts/fontello/config.json

Large diffs are not rendered by default.

20 changes: 15 additions & 5 deletions src/assets/fonts/fontello/fontello.css
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,18 @@
.icon-arrow-back:before {
content: '\e816';
} /* '' */
.icon-plus:before { content: '\e817'; } /* '' */
.icon-upload:before { content: '\e818'; } /* '' */
.icon-copy:before { content: '\e819'; } /* '' */
.icon-check:before { content: '\e81a'; } /* '' */
.icon-danger:before { content: '\e81b'; } /* '' */
.icon-plus:before {
content: '\e817';
} /* '' */
.icon-upload:before {
content: '\e818';
} /* '' */
.icon-copy:before {
content: '\e819';
} /* '' */
.icon-check:before {
content: '\e81a';
} /* '' */
.icon-danger:before {
content: '\e81b';
} /* '' */
2 changes: 1 addition & 1 deletion src/components/Button/Button.styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
border-bottom-right-radius: 0;
}

.btn+.btn {
.btn + .btn {
margin-left: -1px;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
position: relative;
}

[class^='icon-']+span {
[class^='icon-'] + span {
margin-left: 1.2rem;
}

Expand Down
3 changes: 2 additions & 1 deletion src/components/Editor/Editor.styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
}
}

.errorLine, .errorLine+.line-numbers {
.errorLine,
.errorLine + .line-numbers {
background: $secondary-red;
opacity: 0.65;
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/MainContent/MainContent.styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
}
}

.resource-header, .reusable-header {
.resource-header,
.reusable-header {
margin: 0 3rem 3.2rem;
font-size: 2.8rem;
line-height: 3.6rem;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Modals/Contacts/Contacts.styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
.label {
font-weight: 500;
font-size: 1.6rem;
margin-bottom: .8rem;
margin-bottom: 0.8rem;
}

.value {
Expand Down
5 changes: 3 additions & 2 deletions src/components/Modals/SharingForm/SharingForm.styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@
display: flex;
margin-top: 0.8rem;

input, button {
input,
button {
border: 1px solid $secondary-stroke;
border-radius: 4px;
}

>input:not(:last-child) {
> input:not(:last-child) {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
flex: 1 1 auto;
Expand Down
3 changes: 2 additions & 1 deletion src/components/Notifications/Notifications.styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
.notification-success {
&.success {
background: rgba(255, 255, 255, 0.95);
box-shadow: 0 0 36px rgba(27, 17, 40, 0.08), 0 0 12px rgba(27, 17, 40, 0.04), 0 0 4px rgba(27, 17, 40, 0.02);
box-shadow: 0 0 36px rgba(27, 17, 40, 0.08), 0 0 12px rgba(27, 17, 40, 0.04),
0 0 4px rgba(27, 17, 40, 0.02);
border-radius: 21px;
min-height: 0;
color: $main-text;
Expand Down
15 changes: 8 additions & 7 deletions src/components/Resource/ResourceMethods.styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}

&:not(.active) {
+button:not(.active) {
+ button:not(.active) {
margin-left: -1px;
}
}
Expand Down Expand Up @@ -54,27 +54,27 @@
.method-label {
color: #fff;
&.get {
border-color: #0D739E;
border-color: #0d739e;
background-color: $secondary-blue;
}
&.post {
border-color: #679608;
background-color: $secondary-green;
}
&.put {
border-color: #DAA431;
border-color: #daa431;
background-color: $secondary-yellow;
}
&.patch {
border-color: #54A9A8;
border-color: #54a9a8;
background-color: $secondary-azure;
}
&.delete {
border-color: #AD301E;
border-color: #ad301e;
background-color: $secondary-red;
}
&.head {
border-color: #6925D8;
border-color: #6925d8;
background-color: $main-purple;
}
&.options {
Expand All @@ -95,7 +95,8 @@
}

.reusable-resource {
.params-table, .code-view-wrapper {
.params-table,
.code-view-wrapper {
margin-top: 1.2rem;
}

Expand Down
6 changes: 2 additions & 4 deletions src/components/ShareButton/ShareButton.styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
flex-direction: row;
cursor: pointer;

+hr {
+ hr {
height: 1px;
background-color: $secondary-stroke;
}
Expand Down Expand Up @@ -62,7 +62,7 @@
height: 3.2rem;
background-color: $main-purple;

>div {
> div {
display: flex;
align-items: center;
height: 100%;
Expand All @@ -83,5 +83,3 @@
}
}
}


4 changes: 2 additions & 2 deletions src/components/SidebarContent/SidebarGroupItems.styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.sidebar-items {
margin-top: 3.65rem;

+.sidebar-items {
+ .sidebar-items {
margin-top: 2rem;
}

Expand All @@ -25,7 +25,7 @@

> ul {
padding-left: 0;
margin-top: .4rem;
margin-top: 0.4rem;

> li {
padding: 1.4rem 0 1.2rem;
Expand Down
95 changes: 11 additions & 84 deletions src/hooks/useExport.ts
Original file line number Diff line number Diff line change
@@ -1,101 +1,28 @@
import {useContext} from 'react';
import {find} from 'lodash';
import {JDocContext} from 'store';

export function useExport() {
const jdocData = useContext(JDocContext);

const renderHtml: () => Promise<string | null> = async () => {
const styles = document.querySelectorAll('style');
let stylesResult = '';
for (let i = 0; i < styles.length; ++i) {
stylesResult += `<style>${styles[i].innerHTML}</style>`;
}

const hostName = window.location.protocol + '//' + window.location.host;

let scriptLink = '';
let styleLink = '';
if (process.env.NODE_ENV !== 'production') {
const scripts = document.querySelectorAll('script');
scriptLink = find(scripts, (script) => script.src.indexOf('static/js') !== -1)?.src || '';
const links = document.querySelectorAll('link');
styleLink = find(links, (style) => style.href.indexOf('static/css') !== -1)?.href || '';
} else {
scriptLink = hostName + '/static/js/export-main.js';
styleLink = hostName + '/static/css/export-main.css';
}
if (process.env.NODE_ENV === 'production') {
const hostName = window.location.protocol + '//' + window.location.host;
const htmlLink = hostName + '/index-template.html';

if (scriptLink) {
const scriptText = await fetch(scriptLink).then(async (response) => {
const html = await fetch(htmlLink).then(async (response) => {
if (response.ok) {
return await response.text();
}
return '';
});

let cssText: string | undefined = '';
if (styleLink) {
cssText = await fetch(styleLink).then(async (response) => {
if (response.ok) {
return await response.text();
}
});
if (cssText) {
cssText = cssText.replaceAll('../../', `${hostName}/`);
}
}

return `<!DOCTYPE html>
<html lang="en">
<head>
<base href=".">
<meta charset="utf-8"/>
<link rel="icon" href="${hostName + '/favicon.png'}"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="theme-color" content="#000000"/>
<meta name="description" content="Welcome to JSight"/>
<link rel="apple-touch-icon-precomposed" sizes="512x512" href="${
hostName + '/apple-touch-icon-512x512.png'
}"/>
<link rel="apple-touch-icon-precomposed" sizes="180x180" href="${
hostName + '/apple-touch-icon-152x152.png'
}"/>
<meta name="application-name" content="&nbsp;"/>
<meta name="msapplication-TileColor" content="#FFFFFF"/>
<meta name="msapplication-TileImage" content="${hostName + '/mstile-144x144.png'}"/>

<meta property="og:title" content="JSight — the Best API documentation language and tool"/>
<meta property="og:description" content="Are you fed up of OpenAPI? JSight is the simplest, user-friendly, compact language for description of REST API. Feel the difference compared to Swagger!"/>
<meta property="og:type" content="website"/>
<meta property="og:url" content="https://editor.jsight.io"/>
<meta property="og:image" content="https://editor.jsight.io/oggImage.png"/>
<meta property="og:image:type" content="image/png">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="720">
<meta property="og:site_name" content="JSight.io">
<meta property="fb:app_id" content="609425093466922">

<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@jsightapi">
<meta name="twitter:creator" content="@jsightapi">
<link rel="manifest" href="${hostName + '/manifest.json'}"/>
<title>JSight Online Editor</title>
<script>
window.isExport = true;
var jdoc = ${JSON.stringify(jdocData)}
</script>
<script type="module">
${scriptText}
</script>
${cssText ? `<style>${cssText}</style>` : ''}
</head>
<body>
<div id="root"></div>
</body>
</html>
`;
return html
.replace('{{ jdoc }}', JSON.stringify(jdocData))
.replaceAll('../../', `${hostName}/`);
} else {
console.log('Export does not work in development mode');
return null;
}
return null;
};

const saveHtml = async () => {
Expand Down
8 changes: 4 additions & 4 deletions src/styles/_typography.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
font-family: 'fontello';
src: url('../assets/fonts/fontello/fontello.eot');
src: url('../assets/fonts/fontello/fontello.eot?#iefix') format('embedded-opentype'),
url('../assets/fonts/fontello/fontello.woff2') format('woff2'),
url('../assets/fonts/fontello/fontello.woff') format('woff'),
url('../assets/fonts/fontello/fontello.ttf') format('truetype'),
url('../assets/fonts/fontello/fontello.svg#fontello') format('svg');
url('../assets/fonts/fontello/fontello.woff2') format('woff2'),
url('../assets/fonts/fontello/fontello.woff') format('woff'),
url('../assets/fonts/fontello/fontello.ttf') format('truetype'),
url('../assets/fonts/fontello/fontello.svg#fontello') format('svg');
font-weight: normal;
font-style: normal;
}
Expand Down