Merge branch 'news-fix' into 'develop'

fix news

See merge request ldc-web/projets/nature-and-respect!50
This commit is contained in:
Vincent BRIDIER 2024-06-17 13:30:09 +00:00
commit b4ecf09d1f
6 changed files with 22 additions and 26 deletions

View file

@ -25,7 +25,7 @@ class NewsController extends Controller
->orderBy('order')
->paginate();
return \response()->json(\collect($newsList->items())
->map(fn ($newsModel) => $this->renderNews($newsModel)));
->map(fn ($newsModel) => str($this->renderNews($newsModel))->toBase64()));
}
return view('fo.pages.news.index');
}
@ -59,20 +59,18 @@ class NewsController extends Controller
*/
private function renderNews(News $newsModel): string
{
$locale = \app()->currentLocale();
$locale = \app()->currentLocale();
$pictures = $newsModel->picture_list;
return Cache::remember(
"NewsRendered_{$locale}_{$newsModel->id}_{$newsModel->updated_at}",
60,
function () use ($newsModel) {
$pictures = $newsModel->picture_list;
return \base64_encode(\view(
'fo.pages.news.bloc',
[
'newsModel' => $newsModel,
'pictures' => $pictures
]
)->render());
}
fn () => \view(
'fo.pages.news.bloc',
[
'newsModel' => $newsModel,
'pictures' => $pictures
]
)->render()
);
}
}

7
package-lock.json generated
View file

@ -35,6 +35,7 @@
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-vue": "^9.4.0",
"fslightbox": "^3.4.1",
"js-base64": "^3.7.7",
"laravel-vite-plugin": "^0.7.2",
"postcss": "^8.4.23",
"postcss-discard-comments": "^5.1.2",
@ -5983,6 +5984,12 @@
"jiti": "bin/jiti.js"
}
},
"node_modules/js-base64": {
"version": "3.7.7",
"resolved": "https://registry.npmjs.org/js-base64/-/js-base64-3.7.7.tgz",
"integrity": "sha512-7rCnleh0z2CkXhH67J8K1Ytz0b2Y+yxTPL+/KOJoa20hfnVQ/3/T6W/KflYI4bRHRagNeXeU2bkNGI3v1oS/lw==",
"dev": true
},
"node_modules/js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",

View file

@ -42,6 +42,7 @@
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-vue": "^9.4.0",
"fslightbox": "^3.4.1",
"js-base64": "^3.7.7",
"laravel-vite-plugin": "^0.7.2",
"postcss": "^8.4.23",
"postcss-discard-comments": "^5.1.2",

View file

@ -41,6 +41,7 @@
<script lang="ts">
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import axios from "axios";
import { Base64 } from "js-base64";
import { defineComponent } from "vue";
import parseLaravelErrorMessages from "./../../modules/parseLaravelErrorMessages";
import route from "./../../modules/route";
@ -118,18 +119,7 @@ export default defineComponent({
});
},
base64decode(str: string): string {
/**
* Fix issue #40: Problem when there's a '%' in a string.
* https://stackoverflow.com/a/30106551
*/
let decode = atob(str).replace(
"/[\x80-\uffff]/g",
(m) => `%${m.charCodeAt(0).toString(16).padStart(2, "0")}`
).split("").map(function(c) {
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
}).join("");
return decodeURIComponent(decode);
return Base64.decode(str);
},
},
components: { FontAwesomeIcon },

View file

@ -25,7 +25,7 @@
<div class="font-scarletwood text-h3-md lg:text-h2-lg xl:text-h2">
<a href="{{ route('news.show', $newsModel) }}" title="{{ __('Learn more') }}">{{ $newsModel->title }}</a>
</div>
<div>{!! Str::limit(htmlentities(strip_tags($newsModel->content)), 250) !!}</div>
<div>{!! Str::limit(strip_tags($newsModel->content), 250) !!}</div>
</div>
</article>
@endforeach

View file

@ -12,7 +12,7 @@
<h3 class="text-h2-sm md:text-h2-md lg:text-h2-lg xl:text-h2 mb-2 lg:mb-4 font-scarletwood">{{
$newsModel->title
}}</h3>
<div>{!! Str::limit(htmlentities(strip_tags($newsModel->content)), 250) !!}</div>
<div>{!! Str::limit(strip_tags($newsModel->content), 250) !!}</div>
<a title="{{ __('Learn more') }}" class="button brown inline-flex items-center px-4 my-2 mt-6 mr-4 text-sm text-white" href="{{ route('news.show', ['publishedNews' => $newsModel->slug]) }}">
<span>{{ __('Learn more') }}</span>
</a>