Skip to content

Commit

Permalink
update share pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
Reed Nelson committed Aug 15, 2023
1 parent b71c58f commit b50e4c6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/layouts/BlogSingle.astro
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const { title, description, author, categories, image, date, tags } = post.data;
className="social-icons"
title={title}
description={description}
folder={blog_folder}
slug={post.slug}
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/components/Pagination.astro
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ for (let i = 1; i <= totalPages; i++) {
{
totalPages > 1 && (
<nav
class="flex items-center justify-center space-x-3"
class="flex items-center justify-center space-x-3 pb-8 lg:py-0"
aria-label="Pagination"
>
{/* previous */}
Expand Down
11 changes: 6 additions & 5 deletions src/layouts/components/Share.astro
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ const { base_url }: { base_url: string } = config.site;
const {
title,
description,
folder,
slug,
className,
}: { title?: string; description?: string; slug?: string; className?: string } =
}: { title?: string; description?: string; folder?: string; slug?: string; className?: string } =
Astro.props;
---

<ul class={`${className}`}>
<li class="inline-block">
<a href=`mailto:?subject=Article: ${title}&amp;body=Check out this article: ${base_url}/${slug}%0D%0A%0D%0AAbstract:%0D%0A${description}`
<a href=`mailto:?subject=Article: ${title}&amp;body=Check this out: ${base_url}/${folder}/${slug}%0D%0A%0D%0ADescription:%0D%0A${description}%0D%0A%0D%0A`
title="Share by Email"
target="_blank"
rel="noreferrer noopener"
Expand All @@ -30,7 +31,7 @@ const {
<li class="inline-block">
<a
aria-label="facebook share button"
href={`https://facebook.com/sharer/sharer.php?u=${base_url}/${slug}`}
href={`https://facebook.com/sharer/sharer.php?u=${base_url}/${folder}/${slug}`}
target="_blank"
rel="noreferrer noopener"
>
Expand All @@ -40,7 +41,7 @@ const {
<li class="inline-block">
<a
aria-label="twitter share button"
href={`https://twitter.com/intent/tweet/?text=${title}&amp;url=${base_url}/${slug}`}
href={`https://twitter.com/intent/tweet/?text=${title}&amp;url=${base_url}/${folder}/${slug}`}
target="_blank"
rel="noreferrer noopener"
>
Expand All @@ -50,7 +51,7 @@ const {
<li class="inline-block">
<a
aria-label="pinterest share button"
href={`https://pinterest.com/pin/create/button/?url=${base_url}/${slug}&media=&description=${description}`}
href={`https://pinterest.com/pin/create/button/?url=${base_url}/${folder}/${slug}&media=&description=${description}`}
target="_blank"
rel="noreferrer noopener"
>
Expand Down
22 changes: 20 additions & 2 deletions src/lib/utils/similarItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ const similerItems = (currentItem: any, allItems: any, slug: string) => {
let tags: string[] = [];

// set categories
if (currentItem.data.categories.length > 0) {
if (currentItem.data?.categories?.length > 0) {
categories = currentItem.data.categories;
}

// set tags
if (currentItem.data.tags.length > 0) {
if (currentItem.data?.tags?.length > 0) {
tags = currentItem.data.tags;
}

Expand All @@ -30,6 +30,24 @@ const similerItems = (currentItem: any, allItems: any, slug: string) => {
const filterBySlug = mergedItems.filter((product) => product.slug !== slug);

return filterBySlug;

// // The code below needs more testing before the above can be replaced.
// // merged after filter
// const mergedItems = [...filterByCategories, ...filterByTags, ...filterBySpirits, ...filterByBottles];
// // Remove self from list
// const filterBySlug = mergedItems.filter((item) => item.slug !== slug);
// // count instances of each item
// const itemCount = filterBySlug.reduce((accumulator: any, currentItem: any) => {
// accumulator[currentItem.slug] = (accumulator[currentItem.slug] || 0) + 1;
// return accumulator;
// }, {});
// // sort items by number of instances
// const sortedItems = filterBySlug.sort((a: any, b: any) => itemCount[b.slug] - itemCount[a.slug]);
// // remove duplicates
// const uniqueItems = [...new Set(sortedItems.map((item: any) => item.slug))].map((slug: string) => {
// return sortedItems.find((item: any) => item.slug === slug);
// });
// return uniqueItems;
};

export default similerItems;

0 comments on commit b50e4c6

Please sign in to comment.