Skip to content

Commit

Permalink
Merge pull request #222 from jerone/pagemetadata
Browse files Browse the repository at this point in the history
Consistent page metadata

Merging for sizzle... he can test and deploy but we're lagging behind a bit here.
  • Loading branch information
Marti Martz committed Jun 29, 2014
2 parents 7d9eae2 + 9cd49bd commit 7afb77f
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 174 deletions.
17 changes: 5 additions & 12 deletions controllers/_template.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var async = require('async');
var _ = require('underscore');
var pageMetadata = require('../libs/templateHelpers').pageMetadata;

//--- Models
var Group = require('../models/group').Group;
Expand Down Expand Up @@ -29,12 +30,8 @@ exports.example = function (req, res, next) {
options.isMod = authedUser && authedUser.isMod;
options.isAdmin = authedUser && authedUser.isAdmin;

// Metadata
options.title = 'OpenUserJS.org';
options.pageMetaDescription = 'Download Userscripts to enhance your browser.';
var pageMetaKeywords = ['userscript', 'greasemonkey'];
pageMetaKeywords.concat(['web browser']);
options.pageMetaKeywords = pageMetaKeywords.join(', ');
// Page metadata
pageMetadata(options);

//--- Tasks

Expand All @@ -57,12 +54,8 @@ exports.example = function (req, res, next) {
options.isMod = authedUser && authedUser.isMod;
options.isAdmin = authedUser && authedUser.isAdmin;

// Metadata
options.title = 'OpenUserJS.org';
options.pageMetaDescription = 'Download Userscripts to enhance your browser.';
var pageMetaKeywords = ['userscript', 'greasemonkey'];
pageMetaKeywords.concat(['web browser']);
options.pageMetaKeywords = pageMetaKeywords.join(', ');
// Page metadata
pageMetadata(options);

// Scripts: Query
var scriptListQuery = Script.find();
Expand Down
13 changes: 5 additions & 8 deletions controllers/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var helpers = require('../libs/helpers');
var statusCodePage = require('../libs/templateHelpers').statusCodePage;
var updateSessions = require('../libs/modifySessions').update;
var nil = helpers.nil;
var pageMetadata = require('../libs/templateHelpers').pageMetadata;

// This controller is only for use by users with a role of admin or above

Expand Down Expand Up @@ -223,10 +224,8 @@ exports.adminPage = function (req, res, next) {
});
}

// Metadata
options.title = 'Admin | OpenUserJS.org';
options.pageMetaDescription = null;
options.pageMetaKeywords = null;
// Page metadata
pageMetadata(options, 'Admin');

//---
async.parallel(tasks, function (err) {
Expand Down Expand Up @@ -255,10 +254,8 @@ exports.adminApiKeysPage = function (req, res, next) {
});
}

// Metadata
options.title = 'Admin: API Keys | OpenUserJS.org';
options.pageMetaDescription = null;
options.pageMetaKeywords = null;
// Page metadata
pageMetadata(options, ['Site API Keys', 'Admin']);

//--- Tasks

Expand Down
25 changes: 9 additions & 16 deletions controllers/discussion.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var modelQuery = require('../libs/modelQuery');
var cleanFilename = require('../libs/helpers').cleanFilename;
var execQueryTask = require('../libs/tasks').execQueryTask;
var statusCodePage = require('../libs/templateHelpers').statusCodePage;
var pageMetadata = require('../libs/templateHelpers').pageMetadata;

var categories = [
{
Expand Down Expand Up @@ -47,10 +48,8 @@ exports.categoryListPage = function (req, res, next) {
options.isMod = authedUser && authedUser.isMod;
options.isAdmin = authedUser && authedUser.isAdmin;

// Metadata
options.title = 'OpenUserJS.org';
options.pageMetaDescription = '.';
options.pageMetaKeywords = null;
// Page metadata
pageMetadata(options, 'Discussions');

// categoryList
options.categoryList = _.map(categories, modelParser.parseCategory);
Expand Down Expand Up @@ -132,10 +131,8 @@ exports.list = function (req, res, next) {
category = options.category = modelParser.parseCategory(category);
options.canPostTopicToCategory = category.canUserPostTopic(authedUser);

// Metadata
options.title = category.name + ' | OpenUserJS.org';
options.pageMetaDescription = category.description;
options.pageMetaKeywords = null;
// Page metadata
pageMetadata(options, [category.name, 'Discussions'], category.description);

// discussionListQuery
var discussionListQuery = Discussion.find();
Expand Down Expand Up @@ -220,10 +217,8 @@ exports.show = function (req, res, next) {
// Discussion
var discussion = options.discussion = modelParser.parseDiscussion(discussionData);

// Metadata
options.title = discussion.topic + ' | OpenUserJS.org';
options.pageMetaDescription = discussion.topic;
options.pageMetaKeywords = null;
// Page metadata
pageMetadata(options, [discussion.topic, 'Discussions'], discussion.topic);

// commentListQuery
var commentListQuery = Comment.find();
Expand Down Expand Up @@ -297,10 +292,8 @@ exports.newTopic = function (req, res, next) {
//
options.category = category;

// Metadata
options.title = 'New Topic | OpenUserJS.org';
options.pageMetaDescription = null;
options.pageMetaKeywords = null;
// Page metadata
pageMetadata(options, ['New Topic', 'Discussions']);

//---
res.render('pages/newDiscussionPage', options);
Expand Down
28 changes: 9 additions & 19 deletions controllers/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var modelQuery = require('../libs/modelQuery');
var cleanFilename = require('../libs/helpers').cleanFilename;
var getRating = require('../libs/collectiveRating').getRating;
var execQueryTask = require('../libs/tasks').execQueryTask;
var pageMetadata = require('../libs/templateHelpers').pageMetadata;

// clean the name of the group so it is url safe
function cleanGroupName(name) {
Expand Down Expand Up @@ -139,10 +140,8 @@ exports.list = function (req, res) {
options.isMod = authedUser && authedUser.isMod;
options.isAdmin = authedUser && authedUser.isAdmin;

// Metadata
options.title = 'Groups | OpenUserJS.org';
options.pageMetaDescription = null;
options.pageMetaKeywords = null;
// Page metadata
pageMetadata(options, 'Groups');

// groupListQuery
var groupListQuery = Group.find();
Expand Down Expand Up @@ -181,11 +180,10 @@ exports.list = function (req, res) {
// popularGroupList
options.popularGroupList = _.map(options.popularGroupList, modelParser.parseGroup);

// Page <head> meta keywords
var pageMetaKeywords = ['userscript', 'greasemonkey'];
if (options.groupList)
pageMetaKeywords.concat(_.pluck(options.groupList, 'name'));
options.pageMetaKeywords = pageMetaKeywords.join(', ');
// Page metadata
if (options.groupList) {
pageMetadata(options, 'Groups', null, _.pluck(options.groupList, 'name'));
}
};
function render() { res.render('pages/groupListPage', options); }
function asyncComplete() { preRender(); render(); }
Expand Down Expand Up @@ -232,11 +230,9 @@ exports.view = function (req, res, next) {
options.isMod = authedUser && authedUser.isMod;
options.isAdmin = authedUser && authedUser.isAdmin;

// Metadata
// Page metadata
var group = options.group = modelParser.parseGroup(groupData);
options.title = group.name + ' | OpenUserJS.org';
options.pageMetaDescription = null;
options.pageMetaKeywords = null;
pageMetadata(options, [group.name, 'Groups']);

// scriptListQuery
var scriptListQuery = Script.find();
Expand Down Expand Up @@ -284,12 +280,6 @@ exports.view = function (req, res, next) {
// Pagination
options.paginationRendered = pagination.renderDefault(req);

// Page <head> meta keywords
var pageMetaKeywords = ['userscript', 'greasemonkey'];
if (options.groupList)
pageMetaKeywords.push(group.name);
options.pageMetaKeywords = pageMetaKeywords.join(', ');

// Empty list
options.scriptListIsEmptyMessage = 'No scripts.';
if (options.isFlagged) {
Expand Down
62 changes: 37 additions & 25 deletions controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var modelParser = require('../libs/modelParser');
var modelQuery = require('../libs/modelQuery');
var execQueryTask = require('../libs/tasks').execQueryTask;
var removeSession = require('../libs/modifySessions').remove;
var pageMetadata = require('../libs/templateHelpers').pageMetadata;

// The home page has scripts and groups in a sidebar
exports.home = function (req, res) {
Expand All @@ -23,20 +24,17 @@ exports.home = function (req, res) {
var options = {};
var tasks = [];

options.title = 'OpenUserJS.org';
options.pageMetaDescription = 'Download Userscripts to enhance your browser.';
var pageMetaKeywords = ['userscript', 'greasemonkey'];
pageMetaKeywords.concat(['web browser']);
options.pageMetaKeywords = pageMetaKeywords.join(', ');
//
options.librariesOnly = req.query.library !== undefined;

// Page metadata
pageMetadata(options, options.librariesOnly ? 'Libraries' : '');

// Session
authedUser = options.authedUser = modelParser.parseUser(authedUser);
options.isMod = authedUser && authedUser.isMod;
options.isAdmin = authedUser && authedUser.isAdmin;

//
options.librariesOnly = req.query.library !== undefined;

// scriptListQuery
var scriptListQuery = Script.find();

Expand Down Expand Up @@ -124,6 +122,15 @@ exports.home = function (req, res) {
} else {
options.pageHeading = options.isFlagged ? 'Flagged Scripts' : 'Scripts';
}

// Page metadata
if (options.isFlagged) {
if (options.librariesOnly) {
pageMetadata(options, ['Flagged Libraries', 'Moderation']);
} else {
pageMetadata(options, ['Flagged Scripts', 'Moderation']);
}
}
};
function render() { res.render('pages/scriptListPage', options); }
function asyncComplete() { preRender(); render(); }
Expand Down Expand Up @@ -166,14 +173,18 @@ function getSearchResults(req, res, prefixSearch, fullSearch, opts, callback) {
});
opts['$or'] = conditions;

var options = {
'username': user ? user.name : null,
'search': search,
'scriptsList': scriptsList
};

// Page metadata
pageMetadata(options, 'Searching for "' + search + '"');

modelsList.listScripts(opts, req.route.params, baseUrl,
function (scriptsList) {
callback({
'title': 'Searching for "' + search + '"',
'username': user ? user.name : null,
'search': search,
'scriptsList': scriptsList
});
callback(options);
}
);
};
Expand All @@ -192,14 +203,18 @@ exports.search = function (req, res, next) {
exports.toolbox = function (req, res) {
var user = req.session.user;

var options = {
toolbox: true,
username: user ? user.name : null,
scriptsList: scriptsList
};

// Page metadata
pageMetadata(options, 'Toolbox');

modelsList.listScripts({ isLib: true }, req.route.params, '/toolbox',
function (scriptsList) {
res.render('index', {
title: 'The Toolbox',
toolbox: true,
username: user ? user.name : null,
scriptsList: scriptsList
});
res.render('index', options);
});
};

Expand All @@ -224,11 +239,8 @@ exports.register = function (req, res) {
var options = {};
var tasks = [];

//
options.title = 'Register | OpenUserJS.org';
options.pageMetaDescription = 'Login to OpenUserJS.org using OAuth.';
var pageMetaKeywords = ['login', 'register'];
options.pageMetaKeywords = pageMetaKeywords.join(', ');
// Page metadata
pageMetadata(options, 'Login / Register');

// Session
authedUser = options.authedUser = modelParser.parseUser(authedUser);
Expand Down
22 changes: 10 additions & 12 deletions controllers/issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var scriptStorage = require('./scriptStorage');
var discussionLib = require('./discussion');
var execQueryTask = require('../libs/tasks').execQueryTask;
var countTask = require('../libs/tasks').countTask;
var pageMetadata = require('../libs/templateHelpers').pageMetadata;

// List script issues
exports.list = function (req, res, next) {
Expand Down Expand Up @@ -55,10 +56,11 @@ exports.list = function (req, res, next) {
category.categoryPostDiscussionPageUrl = script.scriptOpenIssuePageUrl;
options.category = category;

// Metadata
options.title = script.name + ' Issues' + ' | OpenUserJS.org';
options.pageMetaDescription = category.description;
options.pageMetaKeywords = null; // seperator = ', '
// Page metadata
pageMetadata(
options,
[(open ? 'Issues' : 'Closed Issues'), script.name, (script.isLib ? 'Libraries' : 'Scripts')],
category.description);
options.isScriptIssuesPage = true;

// discussionListQuery
Expand Down Expand Up @@ -181,10 +183,8 @@ exports.view = function (req, res, next) {
tasks.push(execQueryTask(commentListQuery, options, 'commentList'));

function preRender() {
// Metadata
options.title = discussion.topic + ' | OpenUserJS.org';
options.pageMetaDescription = discussion.topic;
options.pageMetaKeywords = null; // seperator = ', '
// Page metadata
pageMetadata(options, [discussion.topic, 'Discussions'], discussion.topic);

// commentList
options.commentList = _.map(options.commentList, modelParser.parseComment);
Expand Down Expand Up @@ -265,10 +265,8 @@ exports.open = function (req, res, next) {

//---
function preRender() {
// Metadata
options.title = 'New Issue for ' + script.name + ' | OpenUserJS.org';
options.pageMetaDescription = '';
options.pageMetaKeywords = null; // seperator = ', '
// Page metadata
pageMetadata(options, ['New Issue', script.name]);
};
function render() { res.render('pages/scriptNewIssuePage', options); }
function asyncComplete() { preRender(); render(); }
Expand Down
Loading

0 comments on commit 7afb77f

Please sign in to comment.