Skip to content

Commit

Permalink
✨ Find favicon in Ghost (#7713)
Browse files Browse the repository at this point in the history
refs #7688

Adds logic in theme settings api to either serve an uploaded favicon and give it the type `upload` or use the default settings `default`, which will serve the favicon from our shared directory.

TODOs for #7688:
- [X] Figure out, which favicon should be used (uploaded or default) -> this PR
- [ ] Serve and redirect the favicon for any browser requests, incl. redirects
- [ ] Upload favicon via `general/settings` and implement basic admin validations -> [WIP] TryGhost/Admin#397
- [ ] Built server side validations
  • Loading branch information
aileen authored and kirrg001 committed Jan 23, 2017
1 parent 5031480 commit 7cb57bf
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
3 changes: 3 additions & 0 deletions core/server/api/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ updateConfigCache = function () {
config.set('theme:timezone', (settingsCache.activeTimezone && settingsCache.activeTimezone.value) || config.get('theme').timezone);
config.set('theme:url', globalUtils.url.urlFor('home', true));
config.set('theme:amp', (settingsCache.amp && settingsCache.amp.value === 'true'));
config.set('theme:favicon', (settingsCache.favicon && settingsCache.favicon.value) ?
{type: 'upload', url: (settingsCache.favicon && settingsCache.favicon.value)} :
{type: 'default', url: config.get('theme:favicon')});

_.each(labsValue, function (value, key) {
config.set('labs:' + key, value);
Expand Down
6 changes: 5 additions & 1 deletion core/server/config/overrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@
"publishAPostBySchedulerToleranceInMinutes": 2
},
"theme": {
"timezone": "Etc/UTC"
"timezone": "Etc/UTC",
"favicon": {
"type": "default",
"url": "core/shared/favicon.ico"
}
},
"maintenance": {
"enabled": false
Expand Down
3 changes: 3 additions & 0 deletions core/server/data/schema/default-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
"cover": {
"defaultValue": ""
},
"favicon": {
"defaultValue": ""
},
"defaultLang": {
"defaultValue": "en_US",
"validations": {
Expand Down
Binary file modified core/shared/favicon.ico
Binary file not shown.
49 changes: 47 additions & 2 deletions core/test/unit/config/index_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ describe('Config', function () {
description: 'casper',
logo: 'casper',
cover: 'casper',
timezone: 'Etc/UTC'
timezone: 'Etc/UTC',
favicon: {
type: 'default',
url: 'core/shared/favicon.ico'
}
}
});
});
Expand All @@ -45,7 +49,7 @@ describe('Config', function () {
var themeConfig = config.get('theme');

// This will fail if there are any extra keys
themeConfig.should.have.keys('title', 'description', 'logo', 'cover', 'timezone');
themeConfig.should.have.keys('title', 'description', 'logo', 'cover', 'timezone', 'favicon');
});

it('should have the correct values for each key', function () {
Expand All @@ -57,6 +61,10 @@ describe('Config', function () {
themeConfig.should.have.property('logo', 'casper');
themeConfig.should.have.property('cover', 'casper');
themeConfig.should.have.property('timezone', 'Etc/UTC');
themeConfig.should.have.property('favicon', {
type: 'default',
url: 'core/shared/favicon.ico'
});
});
});

Expand Down Expand Up @@ -85,6 +93,43 @@ describe('Config', function () {
});
});

describe('Favicon default', function () {
it('should use uploaded favicon', function () {
var themeConfig = config.get('theme');

// Check values are as we expect
themeConfig.should.have.property('favicon', {
type: 'default',
url: 'core/shared/favicon.ico'
});

configUtils.set({
theme: {
favicon: {
type: 'upload',
url: 'content/images/favicon.ico'
}
}
});

config.get('theme').should.have.property('favicon', {
type: 'upload',
url: 'content/images/favicon.ico'
});
});

it('should set theme object with default favicon', function () {
var themeConfig = configUtils.defaultConfig;

// Check values are as we expect
themeConfig.should.have.property('theme');
themeConfig.theme.should.have.property('favicon', {
type: 'default',
url: 'core/shared/favicon.ico'
});
});
});

describe('Index', function () {
it('should have exactly the right keys', function () {
var pathConfig = config.get('paths');
Expand Down

0 comments on commit 7cb57bf

Please sign in to comment.