Skip to content

Commit

Permalink
add ghspa
Browse files Browse the repository at this point in the history
  • Loading branch information
pomianowski committed Jun 15, 2024
1 parent 93fa34e commit ce90810
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 8 deletions.
10 changes: 2 additions & 8 deletions public/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,10 @@
<meta property="og:url" content="https://lepo.co" />
<link rel="canonical" href="https://lepo.co" />
<link rel="shortlink" href="https://lepo.co" />
<style>
.app-nojs,
.app-cookie {
display: none;
}
</style>
<script type="text/javascript" src="ghspa.js"></script>
</head>

<body>

404
</body>

</html>
54 changes: 54 additions & 0 deletions public/ghspa.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
*
* ____ _ ___ _ _ _ _ ___ ___ ____ ____ ____ ____ ____ ___ ____
* | __ | | |__| | | |__] |__] |__| | __ |___ [__ [__ |__] |__|
* |__] | | | | |__| |__] | | | |__] |___ ___] ___] | | |
*
* Easy way to enable Single Page Applications for GitHub Pages
*
* This project was released under MIT license.
*
* @link https://github.com/rafrex/spa-github-pages
* @author Rafael Pedicini <[email protected]>
* @link http://websemantics.ca
* @author Adnan M.Sagar, PhD. <[email protected]>
*
* @param {Object} l, the document current location
* @param {Boolean} projectPages, true by default, https://help.github.com/articles/user-organization-and-project-pages
*
*/

;(function(l, projectPages) {

var repo = projectPages ? '/' + l.pathname.split('/')[1] : ''

/* redirect all 404 trafic to index.html */
function redirect() {
l.replace(l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') + repo + '/?' +
(l.pathname ? 'p=' + l.pathname.replace(/&/g, '~and~').replace(repo, '') : '') +
(l.search ? '&q=' + l.search.slice(1).replace(/&/g, '~and~') : '') +
(l.hash))
}

/* resolve 404 redirects into internal routes */
function resolve() {
if (l.search) {
var q = {}
l.search.slice(1).split('&').forEach(function(v) {
var a = v.split('=')
q[a[0]] = a.slice(1).join('=').replace(/~and~/g, '&')
})
if (q.p !== undefined) {
window.history.replaceState(null, null,
repo + (q.p || '') +
(q.q ? ('?' + q.q) : '') +
l.hash
)
}
}
}

/* if current document is 404 page page, redirect to index.html otherwise resolve */
document.title === '404' ? redirect() : resolve()

}(window.location, window.projectPages || true ))
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<meta property="og:url" content="https://lepo.co" />
<link rel="canonical" href="https://lepo.co" />
<link rel="shortlink" href="https://lepo.co" />
<script type="text/javascript" src="ghspa.js"></script>
<style>
.app-nojs,
.app-cookie {
Expand Down

0 comments on commit ce90810

Please sign in to comment.