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

Fixed build for usage without subdomain #806

Merged
merged 5 commits into from
Nov 10, 2020
Merged
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
7 changes: 6 additions & 1 deletion docker-init.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#!/bin/sh
echo "prepare environment"
# replace BASE_URL constant by REMARK_URL
sed -i "s|https://demo.remark42.com|${REMARK_URL}|g" /srv/web/*.js
sed -i "s|https://demo.remark42.com|${REMARK_URL}|g" /srv/web/*.{js,html}
akellbl4 marked this conversation as resolved.
Show resolved Hide resolved

if [ -n "${SITE_ID}" ]; then
#replace "site_id: 'remark'" by SITE_ID
se -i "s|'remark'|'${SITE_ID}'|g" /srv/web/*.html
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think SITE_ID could be passed via env vars on build time without replacing it after.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if I will build my own docker image this pull request not needed. But I use public docker imageumputun/remark42 and this changes will fix it for usage without subdomain.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing remark could cause side-effects like replacing this word in unexpected palaces.
I could suggest putting unique value or template like expression to places that we want to replace.

Something like {% SITE_ID %} and comment about how it works.
The same we should do for replacing REMARK_URL

Copy link
Contributor Author

@sattellite sattellite Nov 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, current solution is dirty hack. And site_id is hard coded. But this script called only inside docker container. Would not this solution break the usage without docker on bare metal?

If I will add expressions like {% SITE_ID %} and {% REMARK_URL %} it will keep the same after npm run build. And replace expressions to correct values will require postbuild script with sed commands.

I don't know how to fix this correctly, given what I said above.
Or am I wrong?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, you are right. And now we have the issue in bin build. With this PR we will fix the issue only for docker.
Let's use your fix and I will think about how to fix it in all ways for all builds.

fi

if [ -d "/srv/var" ]; then
chown -R app:app /srv/var 2>/dev/null
Expand Down
2 changes: 1 addition & 1 deletion frontend/comments.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

var remark_config = {
site_id: query.site_id,
host: window.location.origin,
host: '<%= htmlWebpackPlugin.options.remarkUrl %>',
url: query.url
};

Expand Down
2 changes: 1 addition & 1 deletion frontend/counter.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<script>
var remark_config = {
site_id: 'remark',
host: window.location.origin,
host: '<%= htmlWebpackPlugin.options.remarkUrl %>',
url: 'https://remark42.com/demo/',
components: ['counter']
};
Expand Down
2 changes: 1 addition & 1 deletion frontend/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@

var remark_config = {
site_id: 'remark',
host: window.location.origin,
host: '<%= htmlWebpackPlugin.options.remarkUrl %>',
url: 'https://remark42.com/demo/',
components: ['embed', 'counter'],
// __colors__: {
Expand Down
2 changes: 1 addition & 1 deletion frontend/last-comments.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<script>
var remark_config = {
site_id: 'remark',
host: window.location.origin,
host: '<%= htmlWebpackPlugin.options.remarkUrl %>',
components: ['last-comments']
};

Expand Down
4 changes: 4 additions & 0 deletions frontend/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,25 @@ module.exports = () => ({
new Html({
template: path.resolve(__dirname, 'index.ejs'),
inject: false,
remarkUrl,
}),
new Html({
template: path.resolve(__dirname, 'counter.ejs'),
filename: 'counter.html',
inject: false,
remarkUrl,
}),
new Html({
template: path.resolve(__dirname, 'last-comments.ejs'),
filename: 'last-comments.html',
inject: false,
remarkUrl,
}),
new Html({
template: path.resolve(__dirname, 'comments.ejs'),
filename: 'comments.html',
inject: false,
remarkUrl,
}),
new MiniCssExtractPlugin({
filename: '[name].css',
Expand Down