2016-09-12 13:53:04 +02:00
|
|
|
var config = require('../../config'),
|
🙇 Blog icon utils and publisher.logo for JSON-LD (#8297)
refs #8221, closes #7688, refs #7558
🙇 Improve meta data publisher logo behaviour
This is a follow-up PR for #8285.
Reasons: The code changes of #8285 caused error messages when falling back to the default `favicon.ico`, as the `image-size` tool doesn't support `ico` files.
This PR takes the logic to decide which logo needs to be listed in our schema into a new fn `blog_logo.js`. There we have now three decisions:
1. If we have a publication **logo**, we'll take that one
2. If we have no publication logo, but an **icon** we'll use this one.
3. If we have none of the above things, we fall back to our default `favicon.ico`
Additional, we're hard coding image dimensions for whenever the logo is an `.ico` file and built and extra decision to not call `image-size` when the dimension are already given.
I will create another follow-up PR, which checks the extension type for the file and offers it as a util.
🛠 Blog icon util
refs #7688
Serve functionality around the blog icon in its own util:
- getIconDimensions -> async function that takes the filepath of on ico file and returns its dimensions
- isIcoImageType -> returns true if file has `.ico` extension
- getIconType -> returns icon-type (`x-icon` or `png`)
- getIconUrl -> returns the absolut or relativ URL for the favicon: `[subdirectory or not]favicon.[ico or png]`
📖 Get .ico sizes for meta data & logo improvement
refs #7558
refs #8221
Use the new `blogIconUtil` in meta data to fetch the dimensions of `.ico` files.
Improvements for `publisher.logo`: We're now returning a hard-coded 'faked' image dimensions value to render an `imageObject` and prevent error our schema (Google structured data). As soon as an image (`.ico` or non-`.ico`) is too large, but - in case of non-`.ico` - a square format, be set the image-dimensions to 60px width and height. This reduces the chances of getting constantly error messages from Googles' webmaster tools.
- add getIconPath util
2017-04-11 23:32:06 +07:00
|
|
|
blogIconUtils = require('../../utils/blog-icon'),
|
2016-09-23 12:05:44 +01:00
|
|
|
utils = require('../../utils');
|
2016-01-17 02:07:52 -08:00
|
|
|
|
2017-04-10 10:30:21 +01:00
|
|
|
/**
|
|
|
|
* Serve either uploaded favicon or default
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
function getFaviconUrl() {
|
🙇 Blog icon utils and publisher.logo for JSON-LD (#8297)
refs #8221, closes #7688, refs #7558
🙇 Improve meta data publisher logo behaviour
This is a follow-up PR for #8285.
Reasons: The code changes of #8285 caused error messages when falling back to the default `favicon.ico`, as the `image-size` tool doesn't support `ico` files.
This PR takes the logic to decide which logo needs to be listed in our schema into a new fn `blog_logo.js`. There we have now three decisions:
1. If we have a publication **logo**, we'll take that one
2. If we have no publication logo, but an **icon** we'll use this one.
3. If we have none of the above things, we fall back to our default `favicon.ico`
Additional, we're hard coding image dimensions for whenever the logo is an `.ico` file and built and extra decision to not call `image-size` when the dimension are already given.
I will create another follow-up PR, which checks the extension type for the file and offers it as a util.
🛠 Blog icon util
refs #7688
Serve functionality around the blog icon in its own util:
- getIconDimensions -> async function that takes the filepath of on ico file and returns its dimensions
- isIcoImageType -> returns true if file has `.ico` extension
- getIconType -> returns icon-type (`x-icon` or `png`)
- getIconUrl -> returns the absolut or relativ URL for the favicon: `[subdirectory or not]favicon.[ico or png]`
📖 Get .ico sizes for meta data & logo improvement
refs #7558
refs #8221
Use the new `blogIconUtil` in meta data to fetch the dimensions of `.ico` files.
Improvements for `publisher.logo`: We're now returning a hard-coded 'faked' image dimensions value to render an `imageObject` and prevent error our schema (Google structured data). As soon as an image (`.ico` or non-`.ico`) is too large, but - in case of non-`.ico` - a square format, be set the image-dimensions to 60px width and height. This reduces the chances of getting constantly error messages from Googles' webmaster tools.
- add getIconPath util
2017-04-11 23:32:06 +07:00
|
|
|
return blogIconUtils.getIconUrl();
|
2017-04-10 10:30:21 +01:00
|
|
|
}
|
2016-01-17 02:07:52 -08:00
|
|
|
|
2017-04-10 10:30:21 +01:00
|
|
|
function getAssetUrl(path, hasMinFile) {
|
|
|
|
// CASE: favicon - this is special path with its own functionality
|
|
|
|
if (path.match(/\/?favicon\.(ico|png)$/)) {
|
|
|
|
// @TODO, resolve this - we should only be resolving subdirectory and extension.
|
|
|
|
return getFaviconUrl();
|
|
|
|
}
|
2016-01-17 02:07:52 -08:00
|
|
|
|
2017-04-10 10:30:21 +01:00
|
|
|
// CASE: Build the output URL
|
|
|
|
// Add subdirectory...
|
|
|
|
var output = utils.url.urlJoin(utils.url.getSubdir(), '/');
|
2016-10-07 23:05:36 +01:00
|
|
|
|
2017-04-10 10:30:21 +01:00
|
|
|
// Optionally add /assets/
|
|
|
|
if (!path.match(/^public/) && !path.match(/^asset/)) {
|
2016-11-14 21:38:55 +07:00
|
|
|
output = utils.url.urlJoin(output, 'assets/');
|
2016-01-17 02:07:52 -08:00
|
|
|
}
|
|
|
|
|
2017-04-10 10:30:21 +01:00
|
|
|
// replace ".foo" with ".min.foo" if configured
|
|
|
|
if (hasMinFile && config.get('useMinFiles') !== false) {
|
2016-02-21 18:48:44 +00:00
|
|
|
path = path.replace(/\.([^\.]*)$/, '.min.$1');
|
2016-01-17 02:07:52 -08:00
|
|
|
}
|
|
|
|
|
2017-04-10 10:30:21 +01:00
|
|
|
// Add the path for the requested asset
|
|
|
|
output = utils.url.urlJoin(output, path);
|
2016-01-17 02:07:52 -08:00
|
|
|
|
2017-04-10 10:30:21 +01:00
|
|
|
// Ensure we have an assetHash
|
|
|
|
// @TODO rework this!
|
|
|
|
if (!config.get('assetHash')) {
|
|
|
|
config.set('assetHash', utils.generateAssetHash());
|
2016-01-17 02:07:52 -08:00
|
|
|
}
|
|
|
|
|
2017-04-10 10:30:21 +01:00
|
|
|
// Finally add the asset hash to the output URL
|
|
|
|
output += '?v=' + config.get('assetHash');
|
|
|
|
|
2016-01-17 02:07:52 -08:00
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = getAssetUrl;
|