Skip to content

Commit

Permalink
Added optional override for site name url
Browse files Browse the repository at this point in the history
  • Loading branch information
hoyce committed Mar 6, 2017
1 parent 28cc179 commit e471cd6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ function prepare(blocks, req, config) {
- `request` is required. Usually the express `req.url` value.
- `app` is optional, defaults to an empty string. Usually the
host URL and the proxy prefix path.
- `siteUrl` is optional, overides default url on the site name only.
- `selectors` is optional, defaults to a plain object with the
following properties:
- `logo` is optional, defaults to `.imageWrapper img`.
Expand Down
26 changes: 16 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const prepareDefaults = {
urls: {
prod: '//www.kth.se',
request: null,
app: ''
app: '',
siteUrl: null
},
siteName: null,
localeText: null,
Expand Down Expand Up @@ -79,12 +80,12 @@ function _getAll (config) {
return Promise.all(
handleBlocks(config)
).then(function (results) {
let result = {}
results.forEach(function (block) {
result[block.blockName] = block.result
})
return result
let result = {}
results.forEach(function (block) {
result[block.blockName] = block.result
})
return result
})
}

/**
Expand All @@ -96,8 +97,8 @@ function handleBlocks (config) {
let blocks = []
let blocksObj = config.blocks
for (let i in blocksObj) {
if(blocksObj.hasOwnProperty(i)) {
if(isLanguage (blocksObj[i])) {
if (blocksObj.hasOwnProperty(i)) {
if (isLanguage(blocksObj[i])) {
blocks.push(_getBlock(config, 'language', true))
} else {
blocks.push(_getBlock(config, i))
Expand All @@ -112,7 +113,7 @@ function handleBlocks (config) {
* @param blockObj the given object.
* @returns {boolean} true if language object.
*/
function isLanguage(blockObj) {
function isLanguage (blockObj) {
return typeof blockObj === 'object'
}

Expand Down Expand Up @@ -219,6 +220,7 @@ module.exports = function (config) {
* @param {String} [config.urls.prod='//www.kth.se']
* @param {String} config.urls.request - Current request URL (usually from req.url).
* @param {String} config.urls.app - The application host name and prefix path.
* @param {String} config.urls.siteUrl - The url to overide app url in sitename if needed.
* @param {Object} [config.selectors] - Optional plain object with CSS selectors.
* @param {String} [config.selectors.logo='.imageWrapper img']
* @param {String} [config.selectors.siteName='.siteName a']
Expand All @@ -242,7 +244,11 @@ module.exports.prepare = function (blocks, config) {
$ = cheerio.load(blocks.title)
$el = $(config.selectors.siteName)
if ($el.length) {
$el.attr('href', config.urls.app)
if (config.urls.siteUrl) {
$el.attr('href', config.urls.siteUrl)
} else {
$el.attr('href', config.urls.app)
}

if (config.siteName) {
$el.text(config.siteName)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kth-node-cortina-block",
"version": "1.0.1",
"version": "1.0.2",
"description": "Node.js module for fetching Cortina blocks and optionally cache using Redis.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit e471cd6

Please sign in to comment.