diff --git a/_recipe_template/README.md b/_recipe_template/README.md index 917be42..f0f7487 100644 --- a/_recipe_template/README.md +++ b/_recipe_template/README.md @@ -24,4 +24,4 @@ Tests have been run in: (Add details here) ## Category -(General Usage|More than Offline|Offline|Web Push) \ No newline at end of file +(General Usage|Beyond Offline|Performance|Offline|Web Push) \ No newline at end of file diff --git a/api-analytics/README.md b/api-analytics/README.md index 91c13c8..0fa0f56 100644 --- a/api-analytics/README.md +++ b/api-analytics/README.md @@ -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 diff --git a/cache-from-zip/README.md b/cache-from-zip/README.md index 04c5f71..6d3bb93 100644 --- a/cache-from-zip/README.md +++ b/cache-from-zip/README.md @@ -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 diff --git a/dependency-injector/README.md b/dependency-injector/README.md index d29b795..2062f20 100644 --- a/dependency-injector/README.md +++ b/dependency-injector/README.md @@ -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 diff --git a/gulpfile.js b/gulpfile.js index bc9b3d5..c6b700d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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) { diff --git a/parseRecipes.js b/parseRecipes.js index 41e2ced..787cf20 100644 --- a/parseRecipes.js +++ b/parseRecipes.js @@ -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.'); @@ -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 + '"'); } @@ -46,12 +50,15 @@ 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', @@ -59,4 +66,25 @@ module.exports = function(recipeSlugs) { 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; }; diff --git a/render-store/README.md b/render-store/README.md index 21f1945..c4357ae 100644 --- a/render-store/README.md +++ b/render-store/README.md @@ -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 diff --git a/request-deferrer/README.md b/request-deferrer/README.md index 2992ba0..7f71100 100644 --- a/request-deferrer/README.md +++ b/request-deferrer/README.md @@ -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 diff --git a/virtual-server/README.md b/virtual-server/README.md index 1f85b63..782b3a9 100644 --- a/virtual-server/README.md +++ b/virtual-server/README.md @@ -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