diff --git a/app/Page.php b/app/Page.php index 5004f33..71977bd 100755 --- a/app/Page.php +++ b/app/Page.php @@ -34,7 +34,7 @@ class Page extends Model * * @var array */ - protected $appends = ['stripped_body']; + protected $appends = ['totally_stripped_body']; /** * Get created at in a human readable format. @@ -61,9 +61,13 @@ public function getUpdatedAtAttribute() * * @return string */ - public function getStrippedBodyAttribute() + public function getTotallyStrippedBodyAttribute() { - return strip_tags($this->attributes['body']); + $string = $this->attributes['body']; + $doubleSpace = strip_tags(str_replace('<', ' <', $string)); + $singleSpace = str_replace(' ', ' ', $doubleSpace); + + return trim($singleSpace); } /** diff --git a/app/Post.php b/app/Post.php index d002bfa..c8b0ef3 100755 --- a/app/Post.php +++ b/app/Post.php @@ -41,7 +41,7 @@ class Post extends Model * * @var array */ - protected $appends = ['stripped_body']; + protected $appends = ['stripped_body', 'totally_stripped_body']; /** * Get the user that owns the post. @@ -84,13 +84,31 @@ public function getUpdatedAtAttribute() } /** - * Get body with the stripped HTML tags. + * Get body with the stripped HTML tags allowing only

tag. * * @return string */ public function getStrippedBodyAttribute() { - return strip_tags($this->attributes['body'], '

'); + $string = $this->attributes['body']; + $doubleSpace = strip_tags(str_replace('<', ' <', $string), '

'); + $singleSpace = str_replace(' ', ' ', $doubleSpace); + + return trim($singleSpace); + } + + /** + * Get body with the stripped HTML tags. + * + * @return string + */ + public function getTotallyStrippedBodyAttribute() + { + $string = $this->attributes['body']; + $doubleSpace = strip_tags(str_replace('<', ' <', $string)); + $singleSpace = str_replace(' ', ' ', $doubleSpace); + + return trim($singleSpace); } /** diff --git a/resources/assets/js/views/page/View.vue b/resources/assets/js/views/page/View.vue index 79f598f..ac68919 100755 --- a/resources/assets/js/views/page/View.vue +++ b/resources/assets/js/views/page/View.vue @@ -47,16 +47,16 @@ return { title: `${this.documentTitle}`, meta: [ - {name: 'description', content: this.page ? this.limitWords(this.page.stripped_body) : ''}, + {name: 'description', content: this.page ? this.limitWords(this.page.totally_stripped_body) : ''}, {name: 'twitter:card', content: 'summary_large_image'}, {name: 'twitter:title', content: this.page ? this.page.title : ''}, - {name: 'twitter:description', content: this.page ? this.limitWords(this.page.stripped_body) : ''}, + {name: 'twitter:description', content: this.page ? this.limitWords(this.page.totally_stripped_body) : ''}, {name: 'twitter:image', content: `${this.getConfig('app_url')}/uploads/images/cover-default.png`}, {property: 'og:type', content: 'website'}, {property: 'og:site_name', content: this.getConfig('company_name')}, {property: 'og:url', content: this.page ? `${this.getConfig('app_url')}/${this.page.slug}` : ''}, {property: 'og:title', content: this.page ? this.page.title : ''}, - {property: 'og:description', content: this.page ? this.limitWords(this.page.stripped_body) : ''}, + {property: 'og:description', content: this.page ? this.limitWords(this.page.totally_stripped_body) : ''}, {property: 'og:image', content: `${this.getConfig('app_url')}/uploads/images/cover-default.png`} ] } diff --git a/resources/assets/js/views/post/View.vue b/resources/assets/js/views/post/View.vue index 9731032..a663ba8 100755 --- a/resources/assets/js/views/post/View.vue +++ b/resources/assets/js/views/post/View.vue @@ -50,16 +50,16 @@ return { title: `${this.documentTitle}`, meta: [ - {name: 'description', content: this.post ? this.limitWords(this.post.stripped_body) : ''}, + {name: 'description', content: this.post ? this.limitWords(this.post.totally_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:description', content: this.post ? this.limitWords(this.post.totally_stripped_body) : ''}, {name: 'twitter:image', content: this.post ? `${this.getConfig('app_url')}/${this.post.cover}` : ''}, {property: 'og:type', content: 'website'}, {property: 'og:site_name', content: this.getConfig('company_name')}, {property: 'og:url', content: this.post ? `${this.getConfig('app_url')}/${this.categorySlug}/${this.post.slug}` : ''}, {property: 'og:title', content: this.post ? this.post.title : ''}, - {property: 'og:description', content: this.post ? this.limitWords(this.post.stripped_body) : ''}, + {property: 'og:description', content: this.post ? this.limitWords(this.post.totally_stripped_body) : ''}, {property: 'og:image', content: this.post ? `${this.getConfig('app_url')}/${this.post.cover}` : ''} ] }