From 126f66d112ea63acb2478321a468f77cf2a1fa1e Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 8 Apr 2015 12:18:58 +0200 Subject: Add sitemap --- index.html | 2 ++ js/main.js | 2 +- js/sitemap.js | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ pages/sitemap.html | 7 +++++++ 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 js/sitemap.js create mode 100644 pages/sitemap.html diff --git a/index.html b/index.html index 22fba1d..61970b2 100644 --- a/index.html +++ b/index.html @@ -45,6 +45,8 @@ setTimeout(function() { Contact Disclaimer + +Sitemap

diff --git a/js/main.js b/js/main.js index 767fd81..fcfd2cb 100644 --- a/js/main.js +++ b/js/main.js @@ -1,7 +1,7 @@ define(function() { 'use strict'; - var all_pages = 'home studying curriculum campus career disclaimer contact'.split(' '); + var all_pages = 'home studying curriculum campus career disclaimer contact sitemap'.split(' '); var cacheBuster = ''; if (/dev/.test(location.search)) { diff --git a/js/sitemap.js b/js/sitemap.js new file mode 100644 index 0000000..65b05c8 --- /dev/null +++ b/js/sitemap.js @@ -0,0 +1,61 @@ +define(['courses', 'campus-coords'], function(courses, campus_coords) { + 'use strict'; + + function Link(name, url) { + this.name = name; + this.url = '#/' + url; + this.children = []; + } + + var add = function(parent, name, url) { + var link = new Link(name, url); + parent.push(link); + return link.children; + }; + var links = []; + add(links, 'Home', 'home'); + add(links, 'Studying', 'studying'); + var course_links = add(links, 'Curriculum', 'curriculum'); + courses.courses.forEach(function(course) { + add(course_links, course.name, 'curriculum/' + course.id); + }); + + var campus_links = add(links, 'Campus', 'campus'); + campus_coords.forEach(function(building) { + add(campus_links, building.name, 'campus/' + building.name); + }); + + add(links, 'Career', 'career'); + add(links, 'Contact', 'contact'); + add(links, 'Disclaimer', 'disclaimer'); + add(links, 'Sitemap', 'sitemap'); + + function make_list(parent, item) { + if (item instanceof Link) { + var li = document.createElement('li'); + var link = document.createElement('a'); + link.href = item.url; + link.textContent = item.name; + li.appendChild(link); + + // child pages + if (item.children.length) { + make_list(li, item.children); + } + + parent.appendChild(li); + } else { + var list = document.createElement('ul'); + item.forEach(function(item) { + make_list(list, item); + }); + parent.appendChild(list); + } + } + + return function() { + var container = document.getElementById('sitemap-content'); + + make_list(container, links); + }; +}); diff --git a/pages/sitemap.html b/pages/sitemap.html new file mode 100644 index 0000000..8d9411e --- /dev/null +++ b/pages/sitemap.html @@ -0,0 +1,7 @@ + + +

Sitemap

+ +
-- cgit v1.2.1