Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F/improvements from villoro #22

Merged
merged 3 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gestkom",
"version": "1.0.2",
"version": "1.0.3",
"description": "Gestkom web page",
"author": "Arnau Villoro <[email protected]>",
"license": "MIT",
Expand Down Expand Up @@ -35,8 +35,7 @@
"react-icons": "^5.0.1",
"react-lite-youtube-embed": "^2.4.0",
"remark-collapse": "^0.1.2",
"remark-toc": "^9.0.0",
"swiper": "^11.0.5"
"remark-toc": "^9.0.0"
},
"devDependencies": {
"@tailwindcss/forms": "^0.5.7",
Expand Down
14 changes: 14 additions & 0 deletions src/layouts/Base.astro
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ const { title, meta_title, description, image, noindex, canonical } =
<meta name="generator" content={Astro.generator} />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />


<!-- Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-KZGPY92C3B"></script>
<script>
/* Only track the page when it is in the main domain. No develop.gestkom.es or localhost */
if (window.location.host==="gestkom.es" || window.location.host==="www.gestkom.es") {
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'G-KZGPY92C3B');
}
</script>

<!-- google font css -->
<AstroFont
config={[
Expand Down
29 changes: 26 additions & 3 deletions src/lib/utils/similarItems.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
// Fisher-Yates shuffle algorithm to get N random elements from an array
function getRandomElements<T>(arr: T[], n: number): T[] {
const shuffled = arr.slice(); // Create a shallow copy of the array
let currentIndex = shuffled.length;
let temporaryValue: T;
let randomIndex: number;

// While there remain elements to shuffle
while (currentIndex !== 0) {
// Pick a remaining element
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;

// Swap it with the current element
temporaryValue = shuffled[currentIndex];
shuffled[currentIndex] = shuffled[randomIndex];
shuffled[randomIndex] = temporaryValue;
}

// Return the first n elements after shuffling
return shuffled.slice(0, n);
}

// similar products
const similarItems = (currentItem: any, allItems: any[], limit: number = 3) => {
let categories: string[] = [];
Expand All @@ -17,10 +40,10 @@ const similarItems = (currentItem: any, allItems: any[], limit: number = 3) => {
(product) => product.slug !== currentItem.slug,
);

// Limit to the specified number of elements
const limitedResults = filterBySlug.slice(0, limit);
// Get N random elements instead of the first N elements
const randomResults = getRandomElements(filterBySlug, limit);

return limitedResults;
return randomResults;
};

export default similarItems;
1 change: 0 additions & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ if (theme.fonts.font_family.secondary) {
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}"],
safelist: [{ pattern: /^swiper-/ }],
darkMode: "class",
theme: {
screens: {
Expand Down
Loading