Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Resolve #157 - Create sort order for sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
darkwing committed Dec 10, 2015
1 parent 940366c commit 3d72ac1
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 28 deletions.
2 changes: 1 addition & 1 deletion _recipe_template/README.md
Expand Up @@ -24,4 +24,4 @@ Tests have been run in:
(Add details here)

## Category
(General Usage|More than Offline|Offline|Web Push)
(General Usage|Beyond Offline|Performance|Offline|Web Push)
2 changes: 1 addition & 1 deletion api-analytics/README.md
Expand Up @@ -12,4 +12,4 @@ As a web app developer, I want to add API tracking capabilities to my web applic
With the use of a service worker, we intercept each request of a client and send some information to a log API.

## Category
More than Offline
Beyond Offline
2 changes: 1 addition & 1 deletion cache-from-zip/README.md
Expand Up @@ -11,4 +11,4 @@ As a web developer I want to distribute my applications as individual zipped pac
While installing the SW, download the zipfile and decompress, caching each of resources.

## Category
More than Offline
Beyond Offline
2 changes: 1 addition & 1 deletion dependency-injector/README.md
Expand Up @@ -15,4 +15,4 @@ Start by looking at `bootstrap.js` to see how a framework could detect which inj
Compare the actual and mocked implementation of the `dialogs` interface in `actual-dialogs.js` and `mock-dialogs.js`.

## Category
More than Offline
Beyond Offline
13 changes: 1 addition & 12 deletions gulpfile.js
Expand Up @@ -22,18 +22,7 @@ var recipeSlugs = glob.sync('./!(dist|node_modules|src|_recipe_template)/').map(
var srcRecipes = recipeSlugs.map(function makePath(name) {
return './' + name + '/**';
});

var recipes = parseRecipes(recipeSlugs).sort(function(recipeA, recipeB) {
if (recipeA.category === recipeB.category) {
return recipeA.difficulty < recipeB.difficulty ? -1 : 1;
}

if (recipeA.category < recipeB.category) {
return -1;
}

return 1;
});
var recipes = parseRecipes(recipeSlugs);

var template = (function() {
function renderContent(content, options) {
Expand Down
46 changes: 37 additions & 9 deletions parseRecipes.js
Expand Up @@ -3,8 +3,16 @@ var glob = require('glob');
var fs = require('fs');
var assert = require('assert');

module.exports = function(recipeSlugs) {
return recipeSlugs.map(function(recipe) {
var difficulties = {
'Advanced': 3,
'Intermediate': 2,
'Beginner': 1
};

var categoryOrder = ['General Usage', 'Offline', 'Beyond Offline', 'Performance', 'Web Push'];

module.exports = function(recipeSlugs) {
var recipes = recipeSlugs.map(function(recipe) {
var tokens = marked.lexer(fs.readFileSync(recipe + '/README.md', 'utf8'));
assert(tokens.length > 1, recipe + ': README.md must have contents.');
assert(tokens[0].type === 'heading', recipe + ': README.md first token must be header.');
Expand All @@ -27,12 +35,8 @@ module.exports = function(recipeSlugs) {
}

var difficultyTerm = getMetadata('Difficulty'), difficulty = 0;
if (difficultyTerm === 'Advanced') {
difficulty = 3;
} else if (difficultyTerm === 'Intermediate') {
difficulty = 2;
} else if (difficultyTerm === 'Beginner') {
difficulty = 1;
if(difficultyTerm in difficulties) {
difficulty = difficulties[difficultyTerm];
} else {
assert(false, recipe + ': Unexpected difficulty value "' + difficultyTerm + '"');
}
Expand All @@ -46,17 +50,41 @@ module.exports = function(recipeSlugs) {
};
});

var category = getMetadata('Category');
assert(categoryOrder.indexOf(category) !== -1, name + ': Unexpected category value "' + category + '"');

return {
name: name,
summary: summary,
difficulty: difficulty,
difficultyTerm: difficultyTerm,
category: getMetadata('Category'),
category: category,
slug: recipe,
srcs: srcs,
demo_ref: recipe + '_demo.html',
demo_index: recipe + '/index.html',
intro_ref: recipe + '.html',
};
});

// Sort categories by category preference, then by difficulty
recipes = recipes.sort(function(recipeA, recipeB) {
// Sort by category
if (categoryOrder.indexOf(recipeA.category) === categoryOrder.indexOf(recipeB.category)) {
// Sort by difficulty
if (recipeA.category === recipeB.category) {
return recipeA.difficulty < recipeB.difficulty ? -1 : 1;
}
if (recipeA.category < recipeB.category) {
return -1;
}
return 1;
} else if (categoryOrder.indexOf(recipeA.category) > categoryOrder.indexOf(recipeB.category)) {
return 1;
} else {
return -1;
}
});

return recipes;
};
2 changes: 1 addition & 1 deletion render-store/README.md
Expand Up @@ -11,4 +11,4 @@ As a web app developer, I want to minimize the load time for revisited resources
Use an offline cache to store the template once it's completely rendered and use this copy upon next requests.

## Category
More than Offline
Beyond Offline
2 changes: 1 addition & 1 deletion request-deferrer/README.md
Expand Up @@ -15,4 +15,4 @@ This advanced technique is intended to integrate with REST APIs and it requires
The solution is a proof of concept and does not include error handling which is a real challenge in this implementation. Some of the problems are stated in the inlined documentation.

## Category
More than Offline
Beyond Offline
2 changes: 1 addition & 1 deletion virtual-server/README.md
Expand Up @@ -15,4 +15,4 @@ Instead of implementing your own logic to distinguish between routes and request
The client code is virtually identical to [that in the API analytics recipe](/api-analytics_index_doc.html) (the report link has been removed). On the contrary, the [remote _Express server_](/api-analytics_server_doc.html) has been completely replaced by the _[ServiceWorkerWare](https://github.com/gaia-components/serviceworkerware) worker_.

## Category
More than Offline
Beyond Offline

0 comments on commit 3d72ac1

Please sign in to comment.