Skip to content

Commit

Permalink
Merge pull request #7 from LR-Tech-Blog/image-post-href
Browse files Browse the repository at this point in the history
  • Loading branch information
LuanRoger authored Jan 7, 2024
2 parents 62342c4 + 21f9398 commit 667c780
Show file tree
Hide file tree
Showing 14 changed files with 1,779 additions and 2,342 deletions.
3,956 changes: 1,660 additions & 2,296 deletions package-lock.json

Large diffs are not rendered by default.

40 changes: 32 additions & 8 deletions src/components/AuthorAvatar.astro
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
---
import type { AuthorProfile } from "../scripts/types/post_types";
import { AuthorProfileImageType } from "../scripts/types/post_types"
import { AuthorProfileImageType } from "../scripts/types/post_types";
import { getGravatarImageUrl } from "../scripts/utils";
import { Image } from 'astro:assets';
import undefinedImage from "../images/undefined.jpg";
import { Image } from "astro:assets";
interface Props {
adm: AuthorProfile
adm: AuthorProfile;
}
const imageSize = 200
const imageSize = 200;
const { adm } = Astro.props
const { adm } = Astro.props;
//TODO: Add default user image
const imageUrl = adm.profileImageType === AuthorProfileImageType.Gravatar ? getGravatarImageUrl(adm.email, imageSize) : adm.profileImageUrl ?? ""
const imageUrl =
adm.profileImageType === AuthorProfileImageType.Gravatar
? getGravatarImageUrl(adm.email, imageSize)
: adm.profileImageUrl;
const imageAlt = adm.profileImageAlt ?? adm.name;
console.log(imageUrl);
---
<Image class="rounded-xl object-cover" src={imageUrl} alt={adm.profileImageAlt}
width={imageSize} height={imageSize}>

{
imageUrl === null ? (
<Image
class="rounded-xl object-cover"
src={undefinedImage}
alt={imageAlt}
width={imageSize}
height={imageSize}
/>
) : (
<Image
class="rounded-xl object-cover"
src={imageUrl}
alt={imageAlt}
width={imageSize}
height={imageSize}
/>
)
}
11 changes: 11 additions & 0 deletions src/components/KeyboardKey.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
interface Props {
kbKey: string
}
const { kbKey } = Astro.props
---

<kbd class="kdb text-text dark:text-dark_text">
{kbKey}
</kbd>
7 changes: 5 additions & 2 deletions src/components/Logo.astro
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
---
import { Image } from 'astro:assets';
import { Image } from "astro:assets";
import lrLogo from "../images/lr_logo.png"
const logoAlt = "Logo LR Tech Blog"
---

<div class="saturate-100 hue-rotate-30 btn btn-ghost h-auto">
<a href="/">
<img src="/images/lr_logo.png" alt="logo-blog" class="transition hover:scale-105" width="90"/>
<Image class:list={"transition hover:scale-105"} src={lrLogo} alt={logoAlt} width={90} />
</a>
</div>
32 changes: 32 additions & 0 deletions src/components/PostImageHero.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
import type { PostImage } from "../scripts/types/post_types";
interface Props {
image: PostImage;
}
const { image } = Astro.props;
const { src, alt, href } = image;
---

{
href === undefined ? (
<img
src={src}
alt={alt}
class="relative rounded-xl mb-5
h-96 w-screen shadow-md object-cover"
transition:animate="slide"
/>
) : (
<a href={href} target="_blank">
<img
src={src}
alt={alt}
class="relative rounded-xl mb-5
h-96 w-screen shadow-md object-cover"
transition:animate="slide"
/>
</a>
)
}
3 changes: 2 additions & 1 deletion src/content/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const blogCollection = defineCollection({
description: z.string(),
image: z.object({
src: z.string(),
alt: z.string()
alt: z.string(),
href: z.string().url().optional(),
})
})
})
Expand Down
8 changes: 7 additions & 1 deletion src/content/posts/components_test.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ image: {
}
---
import DynamicImage from "../../components/DynamicImage.astro"
import KeyboardKey from "../../components/KeyboardKey.astro"

# Header 1
Header 1
Expand Down Expand Up @@ -45,4 +46,9 @@ public class Program

### Vídeo Dinâmico
Este vídeo muda de acordo com o tema do site
<DynamicImage src="/images/posts/components_test/components_test_light.gif" srcDark="/images/posts/components_test/components_test_dark.gif"/>
<DynamicImage src="/images/posts/components_test/components_test_light.gif" srcDark="/images/posts/components_test/components_test_dark.gif"/>

### Teclas de Atalho
<KeyboardKey kbKey="Ctrl" />

A tecla <KeyboardKey kbKey="Ctrl"/> dentro de um paragrafo
3 changes: 2 additions & 1 deletion src/content/posts/hello_world.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ postType: "Showcase"
description: "Esta é a descrição do post"
image: {
"src": "/images/posts/hello_world.jpg",
"alt": "Hello World"
"alt": "Hello World",
"href": "https://www.youtube.com/watch?v=Yw6u6YkTgQ4&ab_channel=LouieZong"
}
---
# Header 1
Expand Down
File renamed without changes
Binary file added src/images/undefined.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 20 additions & 19 deletions src/layouts/PostLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type { AuthorProfile, PostData } from "../scripts/types/post_types";
import PostSideBarLeft from "../components/PostSideBarLeft.astro";
import TagsViewer from "../components/TagsViewer.astro";
import PostTypeTag from "../components/PostTypeBadge.astro";
import PostImageHero from "../components/PostImageHero.astro";
import { imageConfig } from "astro:assets";
interface Props {
id: string;
Expand All @@ -20,26 +22,25 @@ const formatedDate = date.toLocaleDateString("pt-br");
<LayoutBase title={title} bttEnable metaDescription={description}>
<main class="sm:mx-5 md:mx-28">
<div class="flex flex-col gap-5 mb-5">
<PostSideBarLeft/>
<PostSideBarLeft />
<header class="flex flex-col">
<img src={image.src} alt={image.alt} class="relative rounded-xl mb-5
h-96 w-screen shadow-md object-cover" transition:animate="slide"/>
<PostImageHero image={image} />
<div class="flex flex-col mb-3">
<div class="flex flex-row items-center gap-3">
<h1 transition:name={id}>{title}</h1>
<span transition:name={id + postType}>
<PostTypeTag text={postType}/>
</span>
</div>
<small>by {author.name}{formatedDate}</small>
<div class="flex flex-row items-center gap-3">
<h1 transition:name={id}>{title}</h1>
<span transition:name={id + postType}>
<PostTypeTag text={postType} />
</span>
</div>
<small>by {author.name}{formatedDate}</small>
</div>
<TagsViewer tags={tags}/>
</header>
</div>
<article class="self-center">
<Prose>
<slot/>
</Prose>
</article>
<TagsViewer tags={tags} />
</header>
</div>
<article class="self-center">
<Prose>
<slot />
</Prose>
</article>
</main>
</LayoutPage>
</LayoutBase>
9 changes: 1 addition & 8 deletions src/pages/404.astro
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
---
import Icon from "astro-icon";
import LayoutPage from "../layouts/LayoutPage.astro";
import { generateRandomNumber } from "../scripts/utils"
import { getRandomEmoji } from "../scripts/emoji"
export const prerender = false
const iconIndex = generateRandomNumber(0, 20)
const emoji = getRandomEmoji()
console.log(`Icon frequency: ${iconIndex}`);
console.log(`Emojo: ${emoji}`);
---

<LayoutPage title="Você digitou erardo?">
<div class="flex flex-col items-center justify-center sm:text-center h-52">
{
iconIndex > 5 ? <Icon name="file-off" height="40" width="40"/> :
<Icon name="downasaur" height="40" width="40"/>
}
<Icon name="downasaur" height="40" width="40"/>
<h2>
Esta pagina não existe.
</h2>
Expand Down
10 changes: 5 additions & 5 deletions src/pages/about.astro
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
import { getEntry } from "astro:content";
import GravatarAvatar from "../components/AuthorAvatar.astro";
import AuthorAvatar from "../components/AuthorAvatar.astro";
import LayoutPage from "../layouts/LayoutPage.astro";
import type { AuthorProfile, AuthorDescription } from "../scripts/types/post_types";
import type { AuthorProfile } from "../scripts/types/post_types";
import Icon from "astro-icon";
import IconButton from "../components/IconButton.astro";
import Prose from "../components/Prose.astro";
Expand All @@ -21,10 +21,10 @@ const linkedinUrl = adm.linkedin;
---

<LayoutPage title={title}>
<div
<div
class="flex sm:gap-2 md:max-2xl:gap-5 sm:flex-col md:max-2xl:flex-row mb-3"
>
<GravatarAvatar adm={adm} />
<AuthorAvatar adm={adm} />
<div class="flex flex-col sm:gap-2">
<h1>{adm.name}</h1>
<div class="flex flex-row gap-2 items-center">
Expand Down Expand Up @@ -81,4 +81,4 @@ const linkedinUrl = adm.linkedin;
}

customElements.define("social-button", SocialButton);
</script>
</script>
3 changes: 2 additions & 1 deletion src/scripts/types/post_types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface PostImage {
src: string,
alt: string
alt: string,
href?: string | undefined,
}
export interface PostData {
id: string,
Expand Down

0 comments on commit 667c780

Please sign in to comment.