style: cozy!

This commit is contained in:
Ayo 2023-05-12 19:16:43 +02:00
parent 4f7311d02b
commit 19010d2d72
5 changed files with 203 additions and 30 deletions

View file

@ -0,0 +1,56 @@
---
import Form, { FormGroup } from "@astro-reactive/form";
import { Validators } from "@astro-reactive/validator";
export interface Props {
url: string;
}
const { url } = Astro.props;
const form = new FormGroup([
{
name: "url",
value: url,
placeholder: "Put the URL here",
validators: [Validators.required, Validators.minLength(11)],
},
]);
---
<div class="address-bar">
<Form
formGroups={form}
showValidationHints
submitControl={{
type: "submit",
name: "submit",
value: "Get cozy!",
}}
/>
</div>
<style is:inline>
.address-bar {
background-color: orange;
text-align: center;
padding: 0.5em;
width: 100%;
}
input {
width: 100%;
text-align: center;
border: 0px;
border-radius: 5px;
padding: 0.5rem;
}
input[type="text"] {
border: 2px solid brown;
}
input[type="submit"] {
width: 150px;
margin-top: 0.5em;
background-color: brown;
color: white;
font-weight: bolder;
}
</style>

View file

@ -1,23 +1,55 @@
---
import { ArticleData } from "@extractus/article-extractor";
import CSS from "./post.module.scss";
const article = Astro.props.article;
export interface Props {
article: ArticleData;
}
const datePublished =
article.published && new Date(article.published).toDateString();
---
{
article ? (
<article>
<h1>{article.title}</h1>
<p>
by <em>{article.author}</em>
</p>
article && (
<div class="post">
{article.title && <h1 class="title">{article.title}</h1>}
{(article.author || datePublished) && (
<ul class="publish-info">
{article.author && <li>{article.author} </li>}
{datePublished && <li>{datePublished}</li>}
</ul>
)}
<content set:html={article.content} />
</article>
) : (
""
</div>
)
}
<style is:inline>
div.post {
max-width: 550px;
margin: 1em auto;
padding: 1em;
}
@counter-style publish-icons {
system: cyclic;
symbols: "️✍️" "🗓️";
suffix: " ";
}
ul.publish-info {
margin: 1em -1em;
list-style: publish-icons;
}
h1.title {
font-size: xx-large;
}
p,
img {
margin: 1em 0;
}
pre {
white-space: pre-wrap;
}
</style>

31
src/layouts/layout.astro Normal file
View file

@ -0,0 +1,31 @@
---
import "./reset.css";
export interface Props {
title?: string;
}
const appTitle = "Cozy Reader";
const { title = "" } = Astro.props;
---
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{appTitle} {title ? `| ${title}` : ""}</title>
</head>
<body>
<slot />
</body>
</html>
<style is:global>
:root {
--system-ui: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif,
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
html * {
font-family: var(--system-ui);
}
</style>

69
src/layouts/reset.css Normal file
View file

@ -0,0 +1,69 @@
/*
1. Use a more-intuitive box-sizing model.
*/
*,
*::before,
*::after {
box-sizing: border-box;
}
/*
2. Remove default margin
*/
* {
margin: 0;
}
/*
3. Allow percentage-based heights in the application
*/
html,
body {
height: 100%;
}
/*
Typographic tweaks!
4. Add accessible line-height
5. Improve text rendering
*/
body {
line-height: 1.5;
-webkit-font-smoothing: antialiased;
}
/*
6. Improve media defaults
*/
img,
picture,
video,
canvas,
svg {
display: block;
max-width: 100%;
}
/*
7. Remove built-in form typography styles
*/
input,
button,
textarea,
select {
font: inherit;
}
/*
8. Avoid text overflows
*/
p,
h1,
h2,
h3,
h4,
h5,
h6 {
overflow-wrap: break-word;
}
/*
9. Create a root stacking context
*/
#root,
#__next {
isolation: isolate;
}

View file

@ -3,31 +3,16 @@ import Form, { FormGroup } from "@astro-reactive/form";
import { Validators } from "@astro-reactive/validator";
import { extract } from "@extractus/article-extractor";
import { getParams, isURL } from "../utils";
import AddressBar from "../components/address-bar.astro";
import Post from "../components/post.astro";
import Layout from "../layouts/layout.astro";
const params = getParams(Astro.url);
const url: string = params?.url || "";
const article = isURL(url) && (await extract(url));
const form = new FormGroup([
{
name: "url",
value: url,
placeholder: "Put the URL here",
validators: [Validators.required, Validators.minLength(11)],
},
]);
---
<Form
formGroups={form}
showValidationHints
submitControl={{
type: "submit",
name: "submit",
value: "Get cozy!",
}}
/>
<a href="https://github.com/ayoayco/cozy-reader" target="_blank">Source code</a>
<Post article={article} />
<Layout title={article?.title}>
<AddressBar url={url} />
<Post article={article} />
</Layout>