From 7b7f0115e548924b03708913504d867c041cc07a Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 22 Oct 2013 12:23:07 -0400 Subject: [PATCH] closed #432 - added link rel="up" and rel="alternate" to category and topic pages --- public/src/utils.js | 17 +++++++++++ public/templates/header.tpl | 1 + src/webserver.js | 58 ++++++++++++++++++++++++++----------- 3 files changed, 59 insertions(+), 17 deletions(-) diff --git a/public/src/utils.js b/public/src/utils.js index c99fbb99a3..223c8a745c 100644 --- a/public/src/utils.js +++ b/public/src/utils.js @@ -129,6 +129,23 @@ return tags; }, + buildLinkTags: function(tagsArr) { + var tags = '', + tag; + for (var x = 0, numTags = tagsArr.length; x < numTags; x++) { + if (tags.length > 0) tags += "\n\t"; + tag = ' + {link_tags} diff --git a/src/webserver.js b/src/webserver.js index 69e8f6803b..2b3922a8a1 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -53,22 +53,23 @@ var express = require('express'), plugins.fireHook('filter:header.build', custom_header, function(err, custom_header) { var defaultMetaTags = [{ - name: 'viewport', - content: 'width=device-width, initial-scale=1.0, user-scalable=no' - }, { - name: 'content-type', - content: 'text/html; charset=UTF-8' - }, { - name: 'apple-mobile-web-app-capable', - content: 'yes' - }, { - property: 'og:site_name', - content: meta.config.title || 'NodeBB' - }, { - property: 'keywords', - content: meta.config['keywords'] || '' - }], + name: 'viewport', + content: 'width=device-width, initial-scale=1.0, user-scalable=no' + }, { + name: 'content-type', + content: 'text/html; charset=UTF-8' + }, { + name: 'apple-mobile-web-app-capable', + content: 'yes' + }, { + property: 'og:site_name', + content: meta.config.title || 'NodeBB' + }, { + property: 'keywords', + content: meta.config['keywords'] || '' + }], metaString = utils.buildMetaTags(defaultMetaTags.concat(options.metaTags || [])), + linkTags = utils.buildLinkTags(options.linkTags || []), templateValues = { cssSrc: meta.config['theme:src'] || nconf.get('relative_path') + '/vendor/bootstrap/css/bootstrap.min.css', pluginCSS: plugins.cssFiles.map(function(file) { return { path: file } }), @@ -77,6 +78,7 @@ var express = require('express'), csrf: options.res.locals.csrf_token, relative_path: nconf.get('relative_path'), meta_tags: metaString, + link_tags: linkTags, clientScripts: clientScripts, navigation: custom_header.navigation }; @@ -425,7 +427,18 @@ var express = require('express'), }, { property: 'article:section', content: topicData.category_name - }] + }], + linkTags: [ + { + rel: 'alternate', + type: 'application/rss+xml', + href: nconf.get('url') + 'topic/' + tid + '.rss' + }, + { + rel: 'up', + href: nconf.get('url') + 'category/' + topicData.category_slug + } + ] }, function (err, header) { next(err, { header: header, @@ -494,7 +507,18 @@ var express = require('express'), }, { property: "og:type", content: 'website' - }] + }], + linkTags: [ + { + rel: 'alternate', + type: 'application/rss+xml', + href: nconf.get('url') + 'category/' + cid + '.rss' + }, + { + rel: 'up', + href: nconf.get('url') + } + ] }, function (err, header) { next(err, { header: header,