Derive host from the page URL on self-served pages
Previously the pages Remark42 serves from /web/ carried a build-time host.
The `{% REMARK_URL %}` placeholder is substituted during the image and
release-asset builds, both of which write `http://127.0.0.1:8080`. Docker
rewrites it again at container start from REMARK_URL, but a release binary
has no equivalent step, so it serves demo, counter, last-comments and
deleteme pages pointing at the visitor's own loopback address. `counter.ejs`
additionally had that address hardcoded in two "note" links, which no
substitution touched.
These pages are served by Remark42 itself, so the host is whatever origin and
path prefix delivered them. Deriving it from `location` is correct at the root
and under a path prefix alike, and needs no build-time value. Sibling links
are now relative for the same reason.
`site_id` is left as a literal so the startup substitution in docker-init.sh
keeps matching it.
Reported by @andreas-hempel.
Resolves #1996.
This commit is contained in:
committed by
Umputun
parent
8bcfd9e456
commit
8801903d01
@@ -21,13 +21,13 @@
|
||||
<p>
|
||||
First counter with url from data-attribute:
|
||||
<span class="remark42__counter" data-url="https://remark42.com/demo/"></span>
|
||||
(<a href="http://127.0.0.1:8080/web/" target="_blank">note</a>)
|
||||
(<a href="./" target="_blank">note</a>)
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Second counter with url from global remark config:
|
||||
<span class="remark42__counter"></span>
|
||||
(<a href="http://127.0.0.1:8080/web/" target="_blank">note</a>)
|
||||
(<a href="./" target="_blank">note</a>)
|
||||
</p>
|
||||
|
||||
<p>If it can't get url from data-attribute or remark config, it will try to use window.location.href for it.</p>
|
||||
@@ -36,7 +36,7 @@
|
||||
<script>
|
||||
var remark_config = {
|
||||
site_id: 'remark',
|
||||
host: '<%= htmlWebpackPlugin.options.REMARK_URL %>',
|
||||
host: location.origin + location.pathname.replace(/\/[^/]*$/, '').replace(/\/web$/, ''),
|
||||
url: 'https://remark42.com/demo/',
|
||||
components: ['counter'],
|
||||
};
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
<div class="preloader preloader_view_iframe"></div>
|
||||
</div>
|
||||
<script>
|
||||
var remark_config = { host: '<%= htmlWebpackPlugin.options.REMARK_URL %>' };
|
||||
var remark_config = { host: location.origin + location.pathname.replace(/\/[^/]*$/, '').replace(/\/web$/, '') };
|
||||
</script>
|
||||
<script src="deleteme.js"></script>
|
||||
</body>
|
||||
|
||||
@@ -72,11 +72,11 @@
|
||||
</p>
|
||||
<div class="widgets">
|
||||
<div class="widget widgets__widget widgets__comments-widget">
|
||||
<a class="widget__link" href="<%= htmlWebpackPlugin.options.REMARK_URL %>/web/last-comments.html">Last comments widget page</a><br />
|
||||
<iframe class="widget__frame widget__comments-frame" src="<%= htmlWebpackPlugin.options.REMARK_URL %>/web/last-comments.html"></iframe>
|
||||
<a class="widget__link widget__link_page_last-comments" href="./last-comments.html">Last comments widget page</a><br />
|
||||
<iframe class="widget__frame widget__comments-frame"></iframe>
|
||||
</div>
|
||||
<div class="widget widgets__widget widgets__counter-widget">
|
||||
<a class="widget__link" href="<%= htmlWebpackPlugin.options.REMARK_URL %>/web/counter.html">Counter widget page</a><br />
|
||||
<a class="widget__link widget__link_page_counter" href="./counter.html">Counter widget page</a><br />
|
||||
<div class="widget__frame widget__counter-frame">Comments count: <span class="remark42__counter"></span></div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -121,9 +121,15 @@
|
||||
window.REMARK42.changeTheme('dark');
|
||||
});
|
||||
|
||||
var remarkBase = location.origin + location.pathname.replace(/\/[^/]*$/, '').replace(/\/web$/, '');
|
||||
|
||||
document.querySelector('.widget__link_page_last-comments').href = remarkBase + '/web/last-comments.html';
|
||||
document.querySelector('.widget__comments-frame').src = remarkBase + '/web/last-comments.html';
|
||||
document.querySelector('.widget__link_page_counter').href = remarkBase + '/web/counter.html';
|
||||
|
||||
var remark_config = {
|
||||
site_id: 'remark',
|
||||
host: '<%= htmlWebpackPlugin.options.REMARK_URL %>',
|
||||
host: remarkBase,
|
||||
url: window.location.href,
|
||||
components: ['embed', 'counter'],
|
||||
// __colors__: {
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<script>
|
||||
var remark_config = {
|
||||
site_id: 'remark',
|
||||
host: '<%= htmlWebpackPlugin.options.REMARK_URL %>',
|
||||
host: location.origin + location.pathname.replace(/\/[^/]*$/, '').replace(/\/web$/, ''),
|
||||
components: ['last-comments'],
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user