9.1 KiB
Hugo CSS SEO-optimized landing page
Project Structure:
landing-page/
├── archetypes/
│ └── default.md
├── content/
│ └── _index.md
├── layouts/
│ ├── _default/
│ │ ├── baseof.html
│ │ └── landing.html
│ └── partials/
│ ├── header.html
│ ├── footer.html
│ └── cta.html
├── static/
│ ├── css/
│ │ └── main.css
│ └── images/
└── config.toml
Explanation:
- The
archetypesdirectory contains the default template for new content pages. - The
contentdirectory holds the content for the landing page, typically in Markdown format. - The
layoutsdirectory contains the HTML templates for the landing page._default/baseof.htmlis the base template that defines the overall structure of the page._default/landing.htmlis the specific template for the landing page.- The
partialsdirectory contains reusable HTML components such as the header, footer, and CTA.
- The
staticdirectory holds static assets such as CSS stylesheets and images. - The
config.tomlfile contains the configuration settings for the Hugo site.
CSS Code Base:
- Reset and base styles:
/* Reset default browser styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* Set base font styles */
body {
font-family: Arial, sans-serif;
font-size: 16px;
line-height: 1.5;
color: #333;
}
- Layout and spacing:
/* Set a max-width for the content */
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
/* Add spacing between sections */
section {
margin-bottom: 40px;
}
- Typography:
/* Style headings */
h1 {
font-size: 32px;
font-weight: bold;
margin-bottom: 20px;
}
h2 {
font-size: 24px;
font-weight: bold;
margin-bottom: 15px;
}
/* Style paragraphs */
p {
margin-bottom: 15px;
}
- Call-to-action (CTA) button:
/* Style the CTA button */
.cta-button {
display: inline-block;
padding: 12px 24px;
background-color: #007bff;
color: #fff;
text-decoration: none;
border-radius: 4px;
font-weight: bold;
transition: background-color 0.3s ease;
}
.cta-button:hover {
background-color: #0056b3;
}
- Responsive design:
/* Media queries for responsive layout */
@media screen and (max-width: 768px) {
.container {
padding: 10px;
}
h1 {
font-size: 28px;
}
h2 {
font-size: 20px;
}
}
These are just a few examples of CSS styles you can apply to your landing page. You'll need to customize and expand upon them based on your specific design requirements.
Remember to optimize your CSS for performance by minimizing file size, using efficient selectors, and leveraging browser caching.
In the Hugo templates, you'll include the CSS file in the <head> section of your baseof.html file:
<head>
<link rel="stylesheet" href="{{ "css/main.css" | relURL }}">
</head>
This assumes that your CSS file is located at static/css/main.css.
You can then structure your landing page content in the landing.html template using HTML and Hugo's template language. Use the appropriate HTML tags and classes to apply the CSS styles to your content.
Remember to test your landing page across different devices and browsers to ensure a consistent and responsive experience.
Sure, let's perform a logic test and step through what we have so far to ensure we have everything accounted for. We'll check each component of the project structure and make sure it's clear and complete.
Project Structure
1. archetypes/default.md
- Purpose: Provides a default structure for new content.
- Current Content:
--- title: "{{ replace .Name "-" " " | title }}" date: {{ .Date }} draft: true --- - Logic Check: This is correct for creating new content pages. For a single-page landing site, this is minimal but sufficient.
2. content/_index.md
- Purpose: Holds the content for the landing page.
- Current Content:
--- title: "Landing Page" --- # Welcome - Logic Check: This is a good starting point. It sets the title and includes a heading.
3. layouts/
- Purpose: Contains HTML templates for the landing page.
- Structure:
layouts/ ├── _default/ │ ├── baseof.html │ └── landing.html └── partials/ ├── header.html ├── footer.html └── cta.html - Logic Check: The structure is logical. The
_defaultfolder contains the base template and the landing page template. Thepartialsfolder contains reusable HTML components.
4. static/
- Purpose: Holds static assets such as CSS stylesheets and images.
- Structure:
static/ ├── css/ │ └── main.css └── images/ - Logic Check: This is correct. CSS and images are appropriately placed in the
staticdirectory.
5. config.toml
- Purpose: Contains the configuration settings for the Hugo site.
- Content Example:
baseURL = "http://example.org/" languageCode = "en-us" title = "My Landing Page" theme = ""
Detailed Steps to Implement Each Component
layouts/_default/baseof.html
- Purpose: Base template that defines the overall structure of the page.
- Content:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>{{ .Title }}</title> <link rel="stylesheet" href="{{ "css/main.css" | relURL }}"> </head> <body> {{ partial "header.html" . }} {{ block "main" . }}{{ end }} {{ partial "footer.html" . }} </body> </html>
layouts/_default/landing.html
- Purpose: Specific template for the landing page.
- Content:
{{ define "main" }} <main> <section> <h1>{{ .Title }}</h1> {{ .Content }} {{ partial "cta.html" . }} </section> </main> {{ end }}
layouts/partials/header.html
- Purpose: Header component.
- Content:
<header> <h1>My Landing Page</h1> </header>
layouts/partials/footer.html
- Purpose: Footer component.
- Content:
<footer> <p>© 2024 My Landing Page</p> </footer>
layouts/partials/cta.html
- Purpose: Call-to-action component.
- Content:
<div class="cta"> <a href="/contact" class="cta-button">Contact Us</a> </div>
static/css/main.css
-
Purpose: Contains CSS styles for the landing page.
-
Content:
- Reset and base styles:
/* Reset default browser styles */ * { margin: 0; padding: 0; box-sizing: border-box; } /* Set base font styles */ body { font-family: Arial, sans-serif; font-size: 16px; line-height: 1.5; color: #333; }- Layout and spacing:
/* Set a max-width for the content */ .container { max-width: 1200px; margin: 0 auto; padding: 20px; } /* Add spacing between sections */ section { margin-bottom: 40px; }- Typography:
/* Style headings */ h1 { font-size: 32px; font-weight: bold; margin-bottom: 20px; } h2 { font-size: 24px; font-weight: bold; margin-bottom: 15px; } /* Style paragraphs */ p { margin-bottom: 15px; }- Call-to-action (CTA) button:
/* Style the CTA button */ .cta-button { display: inline-block; padding: 12px 24px; background-color: #007bff; color: #fff; text-decoration: none; border-radius: 4px; font-weight: bold; transition: background-color 0.3s ease; } .cta-button:hover { background-color: #0056b3; }- Responsive design:
/* Media queries for responsive layout */ @media screen and (max-width: 768px) { .container { padding: 10px; } h1 { font-size: 28px; } h2 { font-size: 20px; } }
Final Logic Check
- Project Structure: Logical and organized.
- Template Files: Base and partial templates are defined correctly.
- Content File: Initial content for the landing page is set.
- CSS File: Provides basic styling and responsiveness.
Everything seems to be in place for a basic Hugo CSS SEO-optimized landing page with a call to action. You can now proceed to create and deploy your site.
Next Steps
-
Build and Serve the Site:
hugo serverThis will build your site and serve it locally at
http://localhost:1313. -
Customize Content and Styles: Modify the content in
_index.mdand adjust the CSS styles inmain.cssto match your design requirements. -
Deploy the Site: Once satisfied, you can deploy your site to your preferred hosting service. Hugo has a deployment guide to help