Skip to content

Commit

Permalink
add type module while load modern js bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Mineev committed May 5, 2021
1 parent d361564 commit dfdaa11
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 50 deletions.
28 changes: 17 additions & 11 deletions frontend/templates/comments.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@
</article>

<script>
var query = (function() {
var query = (function () {
if (window.location.search.length === 0) return {};
return window.location.search
.substr(1)
.split('&')
.map(function(item) {
.map(function (item) {
return item.split('=');
})
.reduce(function(carry, item) {
.reduce(function (carry, item) {
carry[item[0]] = decodeURIComponent(item[1]);
return carry;
}, {});
Expand All @@ -68,17 +68,23 @@
var remark_config = {
site_id: query.site_id,
host: '<%= htmlWebpackPlugin.options.REMARK_URL %>',
url: query.url
url: query.url,
};
(function(c) {
for(var i = 0; i < c.length; i++){
var d = document, s = d.createElement('script');
s.src = remark_config.host + '/web/' +c[i] +'.js';
(d.head || d.body).appendChild(s);
(function (c, d) {
var r = d.head || d.body;
for (var i = 0; i < c.length; i++) {
var s = d.createElement('script');
var m = 'noModule' in s;
var e = m ? '.mjs' : '.js';
m && (s.type = 'module');
s.async = true;
s.defer = true;
s.src = remark_config.host + '/web/' + c[i] + e;
r.appendChild(s);
}
})(remark_config.components || ['embed']);
})(remark_config.components || ['embed'], document);
}
</script>
<noscript> Please enable JavaScript to view the comments powered by Remark. </noscript>
</body>
</html>
</html>
18 changes: 6 additions & 12 deletions frontend/templates/counter.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,19 @@
site_id: 'remark',
host: '<%= htmlWebpackPlugin.options.REMARK_URL %>',
url: 'https://remark42.com/demo/',
components: ['counter']
components: ['counter'],
};
(function (c, d) {
var r = d.head || d.body;
for (var i = 0; i < c.length; i++) {
var s = d.createElement('script');
var e = '.js';
var r = d.head || d.body;
if ('noModule' in s) {
s.type = 'module';
e = '.mjs';
} else {
s.async = true;
}
var m = 'noModule' in s;
var e = m ? '.mjs' : '.js';
m && (s.type = 'module');
s.async = true;
s.defer = true;
s.src = remark_config.host + '/web/' + c[i] + e;
r.appendChild(s);
}
})(remark_config.components || ['embed'], document);
Expand Down
15 changes: 5 additions & 10 deletions frontend/templates/demo.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,20 @@
// __colors__: {
// "--color0": "red",
// },
theme: theme
theme: theme,
// locale: "ru"
};
(function (c, d) {
var r = d.head || d.body;
for (var i = 0; i < c.length; i++) {
var s = d.createElement('script');
var e = '.js';
var r = d.head || d.body;
if ('noModule' in s) {
s.type = 'module';
e = '.mjs';
}
var m = 'noModule' in s;
var e = m ? '.mjs' : '.js';
m && (s.type = 'module');
s.async = true;
s.defer = true;
s.src = remark_config.host + '/web/' + c[i] + e;
r.appendChild(s);
}
})(remark_config.components || ['embed'], document);
Expand Down
9 changes: 5 additions & 4 deletions frontend/templates/iframe.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,11 @@
</script>
<script>
(function (d) {
const r = d.head || d.body;
const s = document.createElement('script');
s.src = 'noModule' in s ? 'remark.mjs' : 'remark.js';
var r = d.head || d.body;
var s = d.createElement('script');
var m = 'noModule' in s;
s.src = 'remark' + (m ? '.mjs' : '.js');
m && (s.type = 'module');
s.async = true;
s.defer = true;
r.appendChild(s);
Expand Down
20 changes: 7 additions & 13 deletions frontend/templates/last-comments.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
</style>
<% if (htmlWebpackPlugin.options.env === 'production') { %>
<link rel="stylesheet" href="last-comments.css" />
<link rel="stylesheet" href="last-comments.css" />
<% } %>
</head>
<body>
Expand All @@ -27,25 +27,19 @@
var remark_config = {
site_id: 'remark',
host: '<%= htmlWebpackPlugin.options.REMARK_URL %>',
components: ['last-comments']
components: ['last-comments'],
};
(function (c, d) {
var r = d.head || d.body;
for (var i = 0; i < c.length; i++) {
var s = d.createElement('script');
var e = '.js';
var r = d.head || d.body;
if ('noModule' in s) {
s.type = 'module';
e = '.mjs';
} else {
s.async = true;
}
var m = 'noModule' in s;
var e = m ? '.mjs' : '.js';
m && (s.type = 'module');
s.async = true;
s.defer = true;
s.src = remark_config.host + '/web/' + c[i] + e;
r.appendChild(s);
}
})(remark_config.components || ['embed'], document);
Expand Down

0 comments on commit dfdaa11

Please sign in to comment.