Skip to content

Commit

Permalink
extracts function
Browse files Browse the repository at this point in the history
  • Loading branch information
mfacar committed Jul 26, 2024
1 parent 9f0b770 commit 0ff756e
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions app/react/App/Root.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,30 @@ const headTag = (head, CSS, reduxData) => (
</head>
);

const processHtmlContent = content => {
let script = '';
const parser = new HTMLParser(
{
onopentag: (name, _attrib) => {
if (name === 'script') script = '_';
},
ontext: text => {
if (script === '_') {
script = text;
}
},
},
{ decodeEntities: true }
);
parser.write(content);
parser.end();
const htmlContent = content.replace(
content.substring(content.indexOf('<script'), content.indexOf('</script>') + 9),
''
);
return { script, htmlContent };
};

class Root extends Component {
renderInitialData() {
let innerHtml = '';
Expand Down Expand Up @@ -95,25 +119,7 @@ class Root extends Component {
? determineHotAssets(query)
: determineAssets(assets, languageData);



let script = '';
const parser = new HTMLParser(
{
onopentag: (name, _attrib) => {
if (name === 'script') script = '_';
},
ontext: text => {
if (script === '_') {
script = text;
}
},
},
{ decodeEntities: true }
);
parser.write(content);
parser.end();
let htmlContent = content.replace(content.substring(content.indexOf('<script'), content.indexOf('</script>') + 9), '');
const { script, htmlContent } = processHtmlContent(content);
return (
<html lang={language} dir={!languageData.rtl ? 'ltr' : 'rtl'} style={{ fontSize: 'unset' }}>
{headTag(head, CSS, reduxData)}
Expand Down

0 comments on commit 0ff756e

Please sign in to comment.