Skip to content

Commit

Permalink
Publish and publishing tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
trodrigues committed Apr 12, 2016
1 parent 3c61a44 commit a854593
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gh-pages
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function setupNavAnchorListeners() {
* the popstate event), and splits it by '/'.
*/
function loadPage(href) {
href = href.replace(/(^http(s)?:\/\/\w+(:\d+)?\/|^\/)/, '')
href = href.replace(document.baseURI, '')
var urlParts = href.split('/')
var pageName = urlParts[0]
// Attempts to get the object which contains the methods to render and setup
Expand Down
29 changes: 29 additions & 0 deletions bin/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
set -e

PAGES_DIR=./gh-pages
REPO="[email protected]:contentful/product-catalogue-js.git"

echo "Publishing"

# get the gh-pages branch of the repo
if [ ! -d $PAGES_DIR ] ; then
git clone --single-branch --branch gh-pages $REPO $PAGES_DIR
fi

cp -r *.svg *.css *.js pages $PAGES_DIR

# Setup base path and analytics tag
cat index.html | \
sed -e 's/<base href="\/"/<base href="\/product-catalogue-js\/"/g' > \
$PAGES_DIR/index.html

pushd $PAGES_DIR
git add .
git commit -a -m "Page update"
if [ $? -eq 1 ] ; then
echo "Nothing to update"
else
git push origin gh-pages
fi
popd
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!DOCTYPE html>
<html>
<base href='' />
<base href="/" />
<head>
<meta charset="utf-8">
<title>Product Catalogue</title>
Expand All @@ -13,9 +13,9 @@
<div class="nav-container">
<img src="./contentful.svg" width="157" height="32"/>
<ul>
<li><a href="/" data-nav>Products</a></li>
<li><a href="/categories" data-nav>Categories</a></li>
<li><a href="/about" data-nav>About</a></li>
<li><a href="" data-nav>Products</a></li>
<li><a href="categories" data-nav>Categories</a></li>
<li><a href="about" data-nav>About</a></li>
</ul>
</div>
</nav>
Expand Down
4 changes: 2 additions & 2 deletions pages/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ function renderCategoryListPage(categories, productsHTML) {
}

function renderCategoryList(categories) {
return '<li><a href="/categories" data-nav>All</a></li>'+
return '<li><a href="categories" data-nav>All</a></li>'+
categories.map(function (category) {
var fields = category.fields
return '<li>' +
'<img src="' + fields.icon.fields.file.url + '" width="20" height="20" alt="' + fields.categoryDescription + '" title="' + fields.categoryDescription + '" />' +
'<a href="/categories/' + category.sys.id + '" data-nav>' + fields.title + '</a>' +
'<a href="categories/' + category.sys.id + '" data-nav>' + fields.title + '</a>' +
'</li>'
}).join('\n')
}
Expand Down
2 changes: 1 addition & 1 deletion pages/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function renderSingleProduct(product) {
'<div class="product-header">' +
'<h2>' + fields.productName + '</h2>' +
' by ' +
'<a href="/brand/' + fields.brand.sys.id + '" data-nav>' + fields.brand.fields.companyName + '</a>' +
'<a href="brand/' + fields.brand.sys.id + '" data-nav>' + fields.brand.fields.companyName + '</a>' +
'</div>' +
'<p class="product-categories">' +
fields.categories.map(function (category) {
Expand Down
6 changes: 3 additions & 3 deletions pages/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ function renderProductDetails(fields) {
function renderProductHeader(fields) {
return '<div class="product-header">' +
'<h2>' +
'<a href="/product/' + fields.slug + '" data-nav>' +
'<a href="product/' + fields.slug + '" data-nav>' +
fields.productName +
'</a>'+
'</h2>' +
' by ' +
'<a href="/brand/' + fields.brand.sys.id + '" data-nav>' + fields.brand.fields.companyName + '</a>' +
'<a href="brand/' + fields.brand.sys.id + '" data-nav>' + fields.brand.fields.companyName + '</a>' +
'</div>'
}

function renderImage(image, slug) {
if(image && image.fields.file) {
return '<a href="/product/' + slug + '" data-nav>' +
return '<a href="product/' + slug + '" data-nav>' +
'<img src="' + image.fields.file.url + '" width="150" height="150" />' +
'</a>'
} else {
Expand Down

0 comments on commit a854593

Please sign in to comment.