Skip to content

Commit

Permalink
Add open graph protocol with theme covers in posts
Browse files Browse the repository at this point in the history
  • Loading branch information
kutaloweb committed Aug 11, 2018
1 parent 8c457b4 commit 70528e1
Show file tree
Hide file tree
Showing 30 changed files with 100 additions and 82 deletions.
36 changes: 36 additions & 0 deletions app/Repositories/ConfigurationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Configuration;
use Carbon\Carbon;
use File;

class ConfigurationRepository
{
Expand Down Expand Up @@ -111,6 +112,8 @@ public function create($params)
$config->text_value = !is_numeric($value) ? $value : null;
$config->save();
}

$this->setDefaultCover($params);
$this->setLocale($params);
}

Expand Down Expand Up @@ -158,4 +161,37 @@ public function setConfiguration()
\App::setLocale(config('config.locale') ?: 'en');
Carbon::setLocale(config('config.locale') ?: 'en');
}

/**
* @param array $params
*/
protected function setDefaultCover($params)
{
switch ($params['color_theme']) {
case "blue":
case "blue-dark":
case "default":
case "default-dark":
File::copy(public_path() . '/images/cover-default-blue.png', public_path() . '/uploads/images/cover-default.png');
break;
case "green":
case "green-dark":
File::copy(public_path() . '/images/cover-default-green.png', public_path() . '/uploads/images/cover-default.png');
break;
case "megna":
case "megna-dark":
File::copy(public_path() . '/images/cover-default-megna.png', public_path() . '/uploads/images/cover-default.png');
break;
case "purple":
case "purple-dark":
File::copy(public_path() . '/images/cover-default-purple.png', public_path() . '/uploads/images/cover-default.png');
break;
case "red":
case "red-dark":
File::copy(public_path() . '/images/cover-default-red.png', public_path() . '/uploads/images/cover-default.png');
break;
default:
File::copy(public_path() . '/images/cover-default-red.png', public_path() . '/uploads/images/cover-default.png');
}
}
}
4 changes: 3 additions & 1 deletion config/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"facebook_group" => "",
"default_cover" => "uploads/images/cover-default.png",
"maintenance_mode_message" => "Briefly unavailable for scheduled maintenance. Check back in a minute.",
"app_url" => config('app.url'),
],
"default_role" => [
"admin" => "admin",
Expand All @@ -45,7 +46,8 @@
"email_verification",
"facebook_group",
"default_cover",
"maintenance_mode_message"
"maintenance_mode_message",
"app_url"
],
"upload_path" => [
"config" => "uploads/config",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"js-cookie": "^2.1.4",
"laravel-vue-pagination": "^1.0.6",
"uuid": "^3.1.0",
"v-mask": "^1.3.0",
"v-tooltip": "^2.0.0-beta.12",
"vue": "^2.5.16",
"vue-meta": "^1.5.2",
"vue-multiselect": "^2.0.6",
"vue-router": "^2.7.0",
"vue-sortable": "^0.1.3",
Expand Down
Binary file added public/images/cover-default-blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/cover-default-green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/cover-default-megna.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/cover-default-purple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/cover-default-red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file removed public/images/favicon.ico
Empty file.
Binary file modified public/uploads/images/cover-default.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions resources/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Vue from 'vue'
import VueRouter from 'vue-router'
import Form from './services/form'
import helper from './services/helper'
import VueMask from 'v-mask'
import Meta from 'vue-meta'
import VuejsDialog from "vuejs-dialog"
import Sortable from 'vue-sortable'
import paginationRecord from './components/PaginationRecord'
Expand All @@ -39,7 +39,7 @@ Vue.prototype.$last = function (item, list) {
};

Vue.use(VueRouter);
Vue.use(VueMask);
Vue.use(Meta);
Vue.use(VuejsDialog, {
message: i18n.general.proceed_with_request,
okText: i18n.general.yes,
Expand Down
6 changes: 4 additions & 2 deletions resources/assets/js/components/SummernoteEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@
let stringStripper = /(\n|\r| class=(")?Mso[a-zA-Z]+(")?)/g;
let output = input.replace(stringStripper, ' ');
let commentSripper = new RegExp('<!--(.*?)-->', 'g');
output = output.replace(commentSripper, '');
let commentStripper = new RegExp('<!--(.*?)-->', 'g');
output = output.replace(commentStripper, '');
let allowedTags = [
'<h1>', '<h2>', '<h3>', '<h4>', '<h5>', '<h6>', '<p>', '<br>', '<blockquote>', '<code>',
Expand All @@ -121,6 +121,8 @@
output = output.replace(attributeStripper, '');
}
output = output.replace(/[&]nbsp[;]/gi," ");
return output;
},
updatePastedText() {
Expand Down
2 changes: 1 addition & 1 deletion resources/assets/js/layouts/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</div>
</li>
</ul>
<ul v-if="isAuth() && !getTwoFactorCode() && !isScreenLocked()" class="navbar-nav mr-0 my-lg-0">
<ul v-if="isAuth() && !getTwoFactorCode()" class="navbar-nav mr-0 my-lg-0">
<li class="nav-item">
<router-link class="nav-link text-muted waves-effect waves-dark" :to="'/home'">
<i class="fas fa-home fa-fw"></i>
Expand Down
19 changes: 19 additions & 0 deletions resources/assets/js/services/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,24 @@ export default {
toastr.error('500 Internal Server Error');
} else if (error.errors.hasOwnProperty("message"))
toastr.error(error.errors.message[0]);
},

limitWords(textToLimit, wordLimit) {
if (!textToLimit) return;
let finalText = "";
let text2 = textToLimit.replace(/\s+/g, ' ');
let text3 = text2.split(' ');
let numberOfWords = text3.length;
let i = 0;

if (numberOfWords > wordLimit) {
for (i = 0; i < wordLimit; i++) {
finalText = finalText + " " + text3[i] + " ";
}

return finalText + "...";
}

return textToLimit;
}
}
20 changes: 3 additions & 17 deletions resources/assets/js/views/post/PostCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</div>
<div class="card-body">
<h3 class="card-title post-title">{{ post.title }}</h3>
<h5 class="card-text">{{ limitWords(post.stripped_body, 35) }}</h5>
<h5 class="card-text">{{ limitWords(post.stripped_body) }}</h5>
<p class="card-text">
<small class="text-muted card-caps">
{{ post.category.name }} / {{ post.created_at }}
Expand All @@ -20,22 +20,8 @@
export default {
props: ['post'],
methods: {
limitWords(textToLimit, wordLimit) {
let finalText = "";
let text2 = textToLimit.replace(/\s+/g, ' ');
let text3 = text2.split(' ');
let numberOfWords = text3.length;
let i = 0;
if (numberOfWords > wordLimit) {
for (i = 0; i < wordLimit; i++) {
finalText = finalText + " " + text3[i] + " ";
}
return finalText + "...";
}
return textToLimit;
limitWords(str) {
return helper.limitWords(str, 35);
}
}
}
Expand Down
35 changes: 31 additions & 4 deletions resources/assets/js/views/post/View.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@
import pageNotFound from '../errors/PageNotFound'
export default {
metaInfo() {
return {
title: `${this.documentTitle}`,
meta: [
{name: 'description', content: this.post ? this.limitWords(this.post.stripped_body) : ''},
{name: 'twitter:card', content: 'summary_large_image'},
{name: 'twitter:title', content: this.post ? this.post.title : ''},
{name: 'twitter:description', content: this.post ? this.limitWords(this.post.stripped_body) : ''},
{name: 'twitter:image', content: this.post ? `${this.getConfig('app_url')}/${this.post.cover}` : ''},
{property: 'og:locale', content: this.getConfig('locale')},
{property: 'og:site_name', content: this.getConfig('company_name')},
{property: 'og:url', content: this.getConfig('app_url')},
{property: 'og:title', content: this.post ? this.post.title : ''},
{property: 'og:description', content: this.post ? this.limitWords(this.post.stripped_body) : ''},
{property: 'og:image', content: this.post ? `${this.getConfig('app_url')}/${this.post.cover}` : ''}
]
}
},
components: {
pageNotFound,
},
Expand All @@ -40,7 +58,8 @@
category: '',
categoryName: '',
slug: '',
post: {}
post: {},
documentTitle: ''
};
},
mounted() {
Expand All @@ -50,16 +69,24 @@
.then(response => response.data)
.then(response => {
this.post = response.post;
this.categoryName = response.post.category.name;
this.categoryName = this.post ? response.post.category.name : '';
if (this.post) {
document.title = `${helper.getConfig('company_name')} | ${this.post.title}`;
this.documentTitle = `${helper.getConfig('company_name')} | ${this.post.title}`;
} else {
document.title = `${helper.getConfig('company_name')} | ${i18n.general.page_not_found_heading}`;
this.documentTitle = `${helper.getConfig('company_name')} | ${i18n.general.page_not_found_heading}`;
}
})
.catch(error => {
helper.showDataErrorMsg(error);
});
},
methods: {
getConfig(name) {
return helper.getConfig(name);
},
limitWords(str) {
return helper.limitWords(str, 35);
}
}
}
</script>
4 changes: 0 additions & 4 deletions resources/assets/sass/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2566,10 +2566,6 @@ samp {
transition: opacity .3s ease-in-out;
}

.cover-img {
background-color: #fff !important;
}

.card-caps {
text-transform: uppercase;
font-size: 15px;
Expand Down
4 changes: 0 additions & 4 deletions resources/assets/sass/colors/blue-dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ a.link {
background-color: $themecolor !important;
}

.card-img {
background-color: $themecolor;
}

.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
Expand Down
4 changes: 0 additions & 4 deletions resources/assets/sass/colors/blue.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ a.link {
background-color: $themecolor !important;
}

.card-img {
background-color: $themecolor;
}

.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
Expand Down
4 changes: 0 additions & 4 deletions resources/assets/sass/colors/default-dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ a.link {
background-color: $themecolor !important;
}

.card-img {
background-color: $themecolor;
}

.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
Expand Down
4 changes: 0 additions & 4 deletions resources/assets/sass/colors/default.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ a.link {
background-color: $themecolor !important;
}

.card-img {
background-color: $themecolor;
}

.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
Expand Down
4 changes: 0 additions & 4 deletions resources/assets/sass/colors/green-dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ a.link {
background-color: $themecolor !important;
}

.card-img {
background-color: $themecolor;
}

.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
Expand Down
4 changes: 0 additions & 4 deletions resources/assets/sass/colors/green.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ a.link {
background-color: $themecolor !important;
}

.card-img {
background-color: $themecolor;
}

.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
Expand Down
4 changes: 0 additions & 4 deletions resources/assets/sass/colors/megna-dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ a.link {
background-color: $themecolor !important;
}

.card-img {
background-color: $themecolor;
}

.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
Expand Down
4 changes: 0 additions & 4 deletions resources/assets/sass/colors/megna.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ a.link {
background-color: $themecolor !important;
}

.card-img {
background-color: $themecolor;
}

.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
Expand Down
4 changes: 0 additions & 4 deletions resources/assets/sass/colors/purple-dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ a.link {
background-color: $themecolor !important;
}

.card-img {
background-color: $themecolor;
}

.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
Expand Down
4 changes: 0 additions & 4 deletions resources/assets/sass/colors/purple.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ a.link {
background-color: $themecolor !important;
}

.card-img {
background-color: $themecolor;
}

.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
Expand Down
4 changes: 0 additions & 4 deletions resources/assets/sass/colors/red-dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ a.link {
background-color: $themecolor !important;
}

.card-img {
background-color: $themecolor;
}

.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
Expand Down
4 changes: 0 additions & 4 deletions resources/assets/sass/colors/red.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ a.link {
background-color: $themecolor !important;
}

.card-img {
background-color: $themecolor;
}

.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
Expand Down
Loading

0 comments on commit 70528e1

Please sign in to comment.