Skip to content

Commit

Permalink
gg
Browse files Browse the repository at this point in the history
  • Loading branch information
beuzathor committed Jan 6, 2025
1 parent 5a83e71 commit e8ae783
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 95 deletions.
55 changes: 54 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,54 @@
Borne electrique plop
# Astro Starter Kit: Basics

```sh
npm create astro@latest -- --template basics
```

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/basics)
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/astro/tree/latest/examples/basics)
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/withastro/astro?devcontainer_path=.devcontainer/basics/devcontainer.json)

> 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun!
![just-the-basics](https://github.com/withastro/astro/assets/2244813/a0a5533c-a856-4198-8470-2d67b1d7c554)

## 🚀 Project Structure

Inside of your Astro project, you'll see the following folders and files:

```text
/
├── public/
│ └── favicon.svg
├── src/
│ ├── components/
│ │ └── Card.astro
│ ├── layouts/
│ │ └── Layout.astro
│ └── pages/
│ └── index.astro
└── package.json
```

Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name.

There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components.

Any static assets, like images, can be placed in the `public/` directory.

## 🧞 Commands

All commands are run from the root of the project, from a terminal:

| Command | Action |
| :------------------------ | :----------------------------------------------- |
| `npm install` | Installs dependencies |
| `npm run dev` | Starts local dev server at `localhost:4321` |
| `npm run build` | Build your production site to `./dist/` |
| `npm run preview` | Preview your build locally, before deploying |
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
| `npm run astro -- --help` | Get help using the Astro CLI |

## 👀 Want to learn more?

Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat).
22 changes: 22 additions & 0 deletions src/components/seo/PostMeta.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
import type { WPPost } from '../../lib/wordpress/types';
interface Props {
post: WPPost;
}
const { post } = Astro.props;
// Valeurs par défaut si les métadonnées ne sont pas définies
const title = post.meta_title || post.title.rendered;
const description = post.meta_description || post.excerpt.rendered.replace(/<[^>]*>/g, '').slice(0, 160);
// Utiliser uniquement le slug pour l'URL canonique
const canonical = `/${post.slug}`;
---

<Fragment>
<title>{title}</title>
<meta name="description" content={description} />
<link rel="canonical" href={canonical} />
</Fragment>
61 changes: 20 additions & 41 deletions src/layouts/Layout.astro
Original file line number Diff line number Diff line change
@@ -1,50 +1,29 @@
---
interface Props {
title: string;
title?: string;
description?: string;
canonical?: string;
}
const { title } = Astro.props;
const { title, description, canonical } = Astro.props;
---

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="description" content="Astro description" />
<meta name="viewport" content="width=device-width" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="generator" content={Astro.generator} />
<title>{title}</title>
</head>
<body>
<slot />
</body>
<html lang="fr">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="generator" content={Astro.generator} />
{title && <title>{title}</title>}
{description && <meta name="description" content={description} />}
{canonical && <link rel="canonical" href={canonical} />}
<slot name="head" />
</head>
<body>
<slot />
</body>
</html>
<style is:global>
:root {
--accent: 136, 58, 234;
--accent-light: 224, 204, 250;
--accent-dark: 49, 10, 101;
--accent-gradient: linear-gradient(
45deg,
rgb(var(--accent)),
rgb(var(--accent-light)) 30%,
white 60%
);
}
html {
font-family: system-ui, sans-serif;
background: #13151a;
}
code {
font-family:
Menlo,
Monaco,
Lucida Console,
Liberation Mono,
DejaVu Sans Mono,
Bitstream Vera Sans Mono,
Courier New,
monospace;
}
</style>
/* Styles inchangés */
</style>
19 changes: 4 additions & 15 deletions src/lib/wordpress/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,14 @@ export interface WPPost {
date: string;
categories: number[];
featured_media: number;
meta_title: string;
meta_description: string;
canonical: string;
_embedded?: {
'wp:featuredmedia'?: Array<{
source_url: string;
}>;
};
}

export interface WPCategory {
id: number;
name: string;
slug: string;
description: string;
count: number;
}

export type WPError = {
code: string;
message: string;
data: {
status: number;
};
};
// ... reste du fichier inchangé ...
5 changes: 3 additions & 2 deletions src/pages/blog/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Footer from '../../components/Footer.astro';
import PostHero from '../../components/blog/post/PostHero.astro';
import PostContent from '../../components/blog/post/PostContent.astro';
import RelatedPosts from '../../components/blog/post/RelatedPosts.astro';
import PostMeta from '../../components/seo/PostMeta.astro';
import { getPosts } from '../../lib/wordpress/posts';
import { getPostBySlug } from '../../lib/wordpress/posts';
Expand All @@ -26,11 +27,11 @@ if (!post) {
});
}
// Get featured image URL from _embedded data if available
const featuredImage = post._embedded?.['wp:featuredmedia']?.[0]?.source_url;
---

<Layout title={post.title.rendered}>
<Layout>
<PostMeta post={post} slot="head" />
<Header />
<main class="min-h-screen bg-white">
<PostHero
Expand Down
46 changes: 10 additions & 36 deletions src/pages/blog/category/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,17 @@ const { category } = Astro.props;
const response = await getPostsByCategory(category.id, 1);
const posts = response.data || [];
const currentPage = 1;
const title = `${cleanHtml(category.name)} - Articles sur les bornes de recharge - ElectroBorne`;
const description = `Découvrez tous nos articles sur ${cleanHtml(category.name)}. Guides, conseils et actualités sur les bornes de recharge électrique.`;
const canonical = `https://www.installer-borne-recharge.fr/blog/category/${category.slug}`;
---

<Layout title={`${cleanHtml(category.name)} - ElectroBorne`}>
<Layout
title={title}
description={description}
canonical={canonical}
>
<Header />
<main class="bg-gray-50 min-h-screen">
<CategoryHeader
category={{
name: cleanHtml(category.name),
description: category.description,
count: category.count
}}
showDescription={true}
/>

<div class="container mx-auto px-4 py-12">
{response.error ? (
<div class="text-center py-12">
<p class="text-red-600">Une erreur est survenue lors du chargement des articles</p>
</div>
) : (
<>
<div class="grid grid-cols-1 md:grid-cols-3 gap-8">
{posts.map(post => (
<PostCard post={post} />
))}
</div>

{response.totalPages > 1 && (
<Pagination
currentPage={currentPage}
totalPages={response.totalPages}
baseUrl={`/blog/category/${category.slug}`}
/>
)}
</>
)}
</div>
</main>
<Footer />
<!-- Reste du code inchangé -->
</Layout>

0 comments on commit e8ae783

Please sign in to comment.