summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhorus2024-01-16 17:56:14 +0100
committerhorus2024-01-16 17:56:14 +0100
commit94baf5917979db7e06f779844d1dbab6c2936bcc (patch)
tree535fb0d2991a8369cb78751b7198d76b47d203a7
parent870c335022a43b2cb321a5c436b37981a61d2a46 (diff)
downloadcurious-94baf5917979db7e06f779844d1dbab6c2936bcc.tar.gz
minor improvements with hashtag handling
-rw-r--r--app/Libraries/Helper.php31
-rw-r--r--resources/views/layouts/app.blade.php2
2 files changed, 30 insertions, 3 deletions
diff --git a/app/Libraries/Helper.php b/app/Libraries/Helper.php
index 311c466..026abef 100644
--- a/app/Libraries/Helper.php
+++ b/app/Libraries/Helper.php
@@ -73,11 +73,38 @@ class Helper {
if ( "mastodon" == $title ) {
$cat_len= 0;
+
if ( ! $post->getCategories()->get()->isEmpty() ) {
- $categories = "#MostDiscussed ";
+
+ $categories_ar = array("#MostDiscussed");
+
foreach( $post->getCategories()->get() as $cat ) {
- $categories .= "#". $cat->name . " ";
+
+ // uppercase for every word in a possible multi worded hashtag
+ $tmp_cat = ucwords($cat->name);
+
+ // strip everything after / for brevity
+ if ( false !== strpos($tmp_cat, "/") )
+ $tmp_cat = substr($tmp_cat, 0, strpos($tmp_cat, "/"));
+
+ // replace any non-alphanumeric character except underscore, because
+ // it's not allowed to be used in a hashtag
+ $tmp_cat = preg_replace("/[^A-Za-z0-9_]/", '', $tmp_cat);
+
+ // trim just in case
+ $tmp_cat = trim($tmp_cat);
+
+ // if it's not empty, add it to the hashtag array
+ if ( "" != $tmp_cat )
+ $categories_ar[] = "#". $tmp_cat;
}
+
+ // remove possible duplicates (because stripping after "/")
+ $categories_ar = array_unique($categories_ar);
+
+ // join to one string
+ $categories = implode(" ", $categories_ar);
+
$cat_counter = $post->getCategories()->get()->count();
$cat_len = mb_strlen($categories, "UTF-8");
}
diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php
index ca59000..90f1075 100644
--- a/resources/views/layouts/app.blade.php
+++ b/resources/views/layouts/app.blade.php
@@ -10,7 +10,7 @@
<link rel="me" href="https://mstdn.social/@MostDiscussed">
<link rel="me" href="https://mastodon.social/@MostDiscussed">
- <title>{{ config('app.name', 'Laravel') }}@if( "index" != Request::route()->getName() ) - {{ ucwords(Request::route()->getName()) }} Articles @endif</title>
+ <title>{{ config('app.name', 'Laravel') }}@if( ("index" != Request::route()->getName()) && ("show" != Request::route()->getName()) ) - {{ ucwords(Request::route()->getName()) }} Articles @endif</title>
<!-- Scripts -->
<script src="{{ asset('js/app.js') }}" defer></script>