Skip to content

Commit

Permalink
Introduce projectPages global param to switch from User-Org pages to …
Browse files Browse the repository at this point in the history
…Project pages, move css, img and js libs to assets, provide a barebone example
  • Loading branch information
websemantics committed Aug 22, 2016
1 parent d322fe4 commit 780cd6e
Show file tree
Hide file tree
Showing 194 changed files with 64 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .bowerrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"directory": "lib"
"directory": "assets/lib"
}
2 changes: 1 addition & 1 deletion 404.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta charset="utf-8" />
<title>404</title>
<script type="text/javascript" src="ghspa.js">var rootDomain = true</script>
<script type="text/javascript" src="ghspa.js"></script>
</head>

<body>
Expand Down
28 changes: 10 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,37 @@
### [Live demo](http://websemantics.github.io/gh-pages-spa/)


## Install
## Getting Started

Bower
Use the template provided in `example` folder or, follow the steps below,

```
bower install ghspa
```
1- Create a new project with two pages `index.html` and `404.html`.

NPM
2- Install this package with [Bower](https://bower.io/) or [NPM](https://www.npmjs.com/),

```
```bash
npm install ghspa
```


## Getting Started

1- Create a new project with two pages `index.html` and `404.html`.

2- Include file `ghspa.js` in each page, as follows,
3- Include file `ghspa.js` in each page, as follows,

```html
<script type="text/javascript" src="path-to/ghspa.js"></script>
```

3- Set the title of `404.html` page to `404`, as follows,
4- Set `404.html` page title to `404`, as follows,

```html
<title>404</title>
```

4- Optionally, set the global parameter `rootDomain` to `true` to indicate that the project has a custom domain, or is running on an organization repository, as follow,
5- This package supports the [two types of GitHub Pages](https://help.github.com/articles/user-organization-and-project-pages/), **User/Organization** and **Project** Pages. The global parameter `projectPages` is set to `true` by default for **Project** Pages. To enable **User/Organization** Pages or [Custom Domain](https://help.github.com/articles/using-a-custom-domain-with-github-pages/) set it to `false` as follows,

```html
<script type="text/javascript">var rootDomain = true</script>
<script type="text/javascript">var projectPages = false</script>
<script type="text/javascript" src="path-to/ghspa.js"></script>
```

If the project runs on a public repository, set `rootDomain` to `false`, or ignore all together.


## Credits

Expand Down
2 changes: 1 addition & 1 deletion css/index.css → assets/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ h5 {

.masthead .hero h1.ui.header {
margin-top: 0.7em;
margin-bottom: 0em;
margin-bottom: 0.2em;
font-size: 4em;
font-weight: normal;
}
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"ignore": [
"**/.*",
"node_modules",
"lib",
"test",
"tests"
],
Expand Down
17 changes: 17 additions & 0 deletions example/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<title>404</title>
<script type="text/javascript" src="../ghspa.js"></script>
</head>

<body>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</body>

</html>
15 changes: 15 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<title>Github Pages SPA</title>
<script type="text/javascript" src="../ghspa.js"></script>
</head>
<body>
<a href="/gh-pages-spa">Home</a>
<a href="/gh-pages-spa/about">About</a>
<a href="/gh-pages-spa/contact">Contact</a>
</body>

</html>
22 changes: 11 additions & 11 deletions ghspa.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
* | __ | | |__| | | |__] |__] |__| | __ |___ [__ [__ |__] |__|
* |__] | | | | |__| |__] | | | |__] |___ ___] ___] | | |
*
* Enables SPA for Github Pages
* Easy way to enable Single Page Applications for GitHub Pages
*
* This project was released under MIT license.
* This project was released under MIT license.
*
* @link http://websemantics.ca
* @author Web Semantics, Inc. Dev Team <[email protected]>
* @author Adnan M.Sagar, PhD. <[email protected]>
* @link http://websemantics.ca
* @author Web Semantics, Inc. Dev Team <[email protected]>
* @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
*
* @param {Object} l, the document current location
* @param {Boolean} root, true if this project works without a repositoy name (custom domain, organization repository)
*/

;(function(l, root) {
;(function(l, projectPages) {

/* repository name if not working on root domain */
var repo = root ? '' : '/' + l.pathname.split('/')[1]
var repo = projectPages ? '/' + l.pathname.split('/')[1] : ''

/* redirect all 404 trafic to index.html */
function redirect() {
Expand Down Expand Up @@ -50,4 +50,4 @@
/* if current document is 404 page page, redirect to index.html otherwise resolve */
document.title === '404' ? redirect() : resolve()

}(window.location, window.rootDomain || false))
}(window.location, window.projectPages || true ))
16 changes: 8 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<title>Single Page Applications for GitHub Pages - Web Semantics, Inc.</title>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.2/semantic.min.css">
<link rel="stylesheet" type="text/css" href="css/index.css">
<script type="text/javascript" src="lib/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="lib/base-64/base64.js"></script>
<script type="text/javascript" src="lib/larder/larder.js"></script>
<script type="text/javascript" src="lib/gitters/gitters.js"></script>
<script type="text/javascript" src="lib/bragit/bragit.js"></script>
<link rel="stylesheet" type="text/css" href="assets/css/index.css">
<script type="text/javascript" src="assets/lib/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="assets/lib/base-64/base64.js"></script>
<script type="text/javascript" src="assets/lib/larder/larder.js"></script>
<script type="text/javascript" src="assets/lib/gitters/gitters.js"></script>
<script type="text/javascript" src="assets/lib/bragit/bragit.js"></script>
<script>var redirect = location.href</script>
<script type="text/javascript" src="ghspa.js"></script>
<script>
Expand Down Expand Up @@ -41,7 +41,7 @@
</div>
</div>
<div class="ui text hero container">
<img src="img/pikachu.svg">
<img src="assets/img/pikachu.svg">
<h1 class="ui header">Hi. I'm Pikachu.</h1>
<div class="ui right big yellow image label">
<i class="info icon"></i>
Expand Down Expand Up @@ -93,7 +93,7 @@ <h4 class="ui header">Links</h4>
</div>
<div class="seven wide column">
<h4 class="ui header">Company</h4>
<p>Built with <img src="img/heart.svg">by Web Semantics, Inc.</p>
<p>Built with <img src="assets/img/heart.svg">by Web Semantics, Inc.</p>
</div>
</div>
</div>
Expand Down

0 comments on commit 780cd6e

Please sign in to comment.