Skip to content

Commit

Permalink
index.js: Fixed link prefixing for github pages
Browse files Browse the repository at this point in the history
  • Loading branch information
souravtecken committed Jun 28, 2020
1 parent d384ccf commit 049795b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion components/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const Navbar = () => (
<div className="collapse navbar-collapse" id="navbarColor03">
<ul className="navbar-nav mr-auto">
<li className="nav-item active">
<a className="nav-link" href="/">Home <span className="sr-only">(current)</span></a>
<a className="nav-link" href={`${process.env.ASSET_PREFIX}/`}>Home <span className="sr-only">(current)</span></a>
</li>
</ul>
{/* <form className="form-inline my-2 my-lg-0">
Expand Down
15 changes: 15 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
const webpack = require('webpack');

const isProduction = (process.env.NODE_ENV || 'production') === 'production';

const assetPrefix = isProduction ? '/editorials' : '';

module.exports = {
exportTrailingSlash: true,
assetPrefix: assetPrefix,
webpack: config => {
config.plugins.push(
new webpack.DefinePlugin({
'process.env.ASSET_PREFIX': JSON.stringify(assetPrefix),
}),
)
return config
},
}
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"react-dom": "^16.13.1",
"react-syntax-highlighter": "^12.2.1",
"remark": "^12.0.0",
"remark-html": "^11.0.2"
"remark-html": "^11.0.2",
"webpack": "^4.43.0"
}
}
4 changes: 3 additions & 1 deletion pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export default function Home({ db }) {
<td>{key}</td>
<td>{db[key].title}</td>
<td>{db[key].difficulty}</td>
<Link href={`./problems/${key}`}><td>View editorial</td></Link>
<Link href={`/problems/${key}`} as={`${process.env.ASSET_PREFIX}/problems/${key}`}>
<td>View editorial</td>
</Link>
</tr>
))
}
Expand Down

0 comments on commit 049795b

Please sign in to comment.