This commit is contained in:
DarkCat09 2023-06-18 18:10:29 +04:00
parent 70c223f378
commit 8849d70735
16 changed files with 428 additions and 69 deletions

View file

@ -1,8 +1,16 @@
import { defineConfig } from 'astro/config'; import { defineConfig } from 'astro/config';
import compress from "astro-compress"; import compress from "astro-compress";
import remarkUnwrapImages from 'remark-unwrap-images';
// https://astro.build/config // https://astro.build/config
export default defineConfig({ export default defineConfig({
integrations: [compress()] integrations: [compress()],
build: {
format: "directory"
},
markdown: {
syntaxHighlight: "shiki",
remarkPlugins: [remarkUnwrapImages],
},
}); });

29
package-lock.json generated
View file

@ -9,7 +9,8 @@
"dependencies": { "dependencies": {
"astro": "^2.3.0", "astro": "^2.3.0",
"astro-compress": "^1.1.42", "astro-compress": "^1.1.42",
"less": "^4.1.3" "less": "^4.1.3",
"remark-unwrap-images": "^3.0.1"
} }
}, },
"node_modules/@ampproject/remapping": { "node_modules/@ampproject/remapping": {
@ -4712,6 +4713,21 @@
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
} }
}, },
"node_modules/remark-unwrap-images": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/remark-unwrap-images/-/remark-unwrap-images-3.0.1.tgz",
"integrity": "sha512-5VUY0n+J9lPTPfkct5S3/SbutryBjp8J/4mbgtlkDrOk3h8jde0hyqdYUJOoJKherZezS08tjd6i4+nnQ+wl5w==",
"dependencies": {
"@types/mdast": "^3.0.0",
"hast-util-whitespace": "^2.0.0",
"unified": "^10.0.0",
"unist-util-visit": "^4.0.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
}
},
"node_modules/resolve": { "node_modules/resolve": {
"version": "1.22.2", "version": "1.22.2",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.2.tgz", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.2.tgz",
@ -9231,6 +9247,17 @@
"unist-util-visit": "^4.1.0" "unist-util-visit": "^4.1.0"
} }
}, },
"remark-unwrap-images": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/remark-unwrap-images/-/remark-unwrap-images-3.0.1.tgz",
"integrity": "sha512-5VUY0n+J9lPTPfkct5S3/SbutryBjp8J/4mbgtlkDrOk3h8jde0hyqdYUJOoJKherZezS08tjd6i4+nnQ+wl5w==",
"requires": {
"@types/mdast": "^3.0.0",
"hast-util-whitespace": "^2.0.0",
"unified": "^10.0.0",
"unist-util-visit": "^4.0.0"
}
},
"resolve": { "resolve": {
"version": "1.22.2", "version": "1.22.2",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.2.tgz", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.2.tgz",

View file

@ -12,6 +12,7 @@
"dependencies": { "dependencies": {
"astro": "^2.3.0", "astro": "^2.3.0",
"astro-compress": "^1.1.42", "astro-compress": "^1.1.42",
"less": "^4.1.3" "less": "^4.1.3",
"remark-unwrap-images": "^3.0.1"
} }
} }

BIN
public/forest.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 KiB

View file

@ -0,0 +1,67 @@
---
import TextBox from "./TextBox.astro";
import Icon from "./Icon.astro";
export interface Props {
method: "get" | "post";
}
const { method } = Astro.props;
---
<form method={method} action="https://searx.dc09.ru/search">
<span slot="label" id="method-and-submit">
<span>
Method:
{method == "get" ? <b>GET</b> : <a href="/blog/search">GET</a>}
{method == "post" ? <b>POST</b> : <a href="/blog/search_post">POST</a>}
</span>
<span>
<label id="search-btn">
<span>
Search
</span>
<input type="submit" value="Search">
</label>
</span>
</span>
<TextBox id="q" label="Query" size={27} value="<write here> site:https://dc09.ru/blog" />
<input type="hidden" name="engines" value="google,yahoo">
</form>
<style lang="less">
#method-and-submit {
width: 100%;
display: inline-flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
#search-btn {
input[type=submit] {
display: none;
}
span {
cursor: pointer;
display: inline-flex;
justify-content: center;
align-items: center;
padding: 0 0.625rem;
font-size: 1.1rem;
background-color: var(--bg);
border: 0.125rem dashed var(--bg-sec);
border-radius: var(--bdrs);
transition: background-color 0.2s ease 0s;
&:hover {
background-color: var(--bg-sec);
}
}
}
</style>

View file

@ -1,66 +0,0 @@
---
import Icon from "./Icon.astro";
import ThemeModal from "./ThemeModal.astro";
---
<ThemeModal />
<nav>
<ul>
<li>
<a href="#">
<Icon code="&#xf015;" />
Homepage
</a>
</li>
<li>
<a href="#skills">
Skills
</a>
</li>
<li>
<a href="#projects">
Projects
</a>
</li>
</ul>
<ul>
<li>
<a href="#theme">
Theme
</a>
</li>
<li>
<a href="#dc09ru">
Services
</a>
</li>
<li>
<a href="https://blog.dc09.ru">
Blog
</a>
</li>
</ul>
</nav>
<style lang="less">
nav {
margin: 0.4rem;
display: flex;
flex-direction: row;
justify-content: space-between;
}
ul {
margin: 0;
padding: 0;
list-style: none;
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
li {
padding: 0 0.6rem;
font-size: 1.1rem;
}
</style>

View file

@ -0,0 +1,22 @@
# Abc
## def
```
123
```
_Hello_
**world**
|Col1|Col2|Col3|
|:--:|:---|---:|
|Some|cool|data|
|12345678|11|00|
```js
console.log(Object.keys({a:'a',b:'b'}))
```
> Quotation
![Forest](https://dc09.ru/forest.jpg)

View file

@ -0,0 +1,15 @@
The standard Lorem Ipsum passage, used since the 1500s
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"
1914 translation by H. Rackham
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"
Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."
1914 translation by H. Rackham
"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."

1
src/env.d.ts vendored
View file

@ -1 +1,2 @@
/// <reference path="../.astro/types.d.ts" />
/// <reference types="astro/client" /> /// <reference types="astro/client" />

View file

@ -0,0 +1,25 @@
---
import Layout from "./Layout.astro";
import Menu from "./Menu.astro";
import MenuItem from "../components/MenuItem.astro";
export interface Props {
title: string;
description: string;
}
const { title, description } = Astro.props;
---
<Layout title={"Blog | " + title} description={description}>
<slot name="metadata" slot="metadata" />
<Menu>
<MenuItem name="Homepage" icon="&#xf015;" link="/blog" />
<MenuItem name="Shorts" icon="&#xf0e7;" link="/blog/shorts" />
<MenuItem name="Random post" icon="&#xf522;" link="/blog/random" />
<MenuItem name="Search" icon="&#xf002;" link="/blog/search" />
</Menu>
<main>
<slot />
</main>
</Layout>

171
src/pages/blog/[slug].astro Normal file
View file

@ -0,0 +1,171 @@
---
import BlogLayout from "../../layouts/BlogLayout.astro";
import Icon from "../../components/Icon.astro";
import { getCollection } from "astro:content";
import { AstroComponentFactory } from "astro/dist/runtime/server";
import { MarkdownHeading } from "astro";
type postType = {
id: string;
slug: string;
body: string;
collection: "blog";
data: any;
} & {
render(): Promise<{
Content: AstroComponentFactory;
headings: MarkdownHeading[];
remarkPluginFrontmatter: Record<string, any>;
}>;
};
export async function getStaticPaths() {
const posts = await getCollection("blog");
return posts.map((post) => ({
params: {
slug: post.slug,
},
props: { post },
}));
}
const { slug } = Astro.params;
const post: postType = Astro.props.post;
const postObj = await post.render();
const title = postObj.headings[0]?.text || '';
const description = post.body
.replace(/[^A-Za-z0-9А-ЯЁа-яё+-]/g, ' ')
.replace(/ {2,}/g, ' ')
.slice(0, 100)
.trim() + '\u2026'; // 2026 = ellipsis
let dateStr = slug.split("-", 1)[0];
let date: string | undefined;
if (isNaN(Number(dateStr))) {
dateStr = undefined;
}
else {
date =
`${dateStr.slice(0,4)}-` +
`${dateStr.slice(4,6)}-` +
`${dateStr.slice(6,8)}`;
}
const image = (post.body.match(/(?:\s|^)!\[.*\]\((.*?)\)/) || [])[1];
---
<BlogLayout title={title} description={description}>
<Fragment slot="metadata">
<meta property="og:type" content="article" />
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
<meta property="og:image" content={image} />
<meta property="article:published_time" content={date} />
<meta property="article:author" content="DarkCat09" />
<meta property="twitter:card" content="summary" />
<meta property="twitter:title" content={title} />
<meta property="twitter:description" content={description} />
<meta property="twitter:image" content={image} />
</Fragment>
<span id="link-icon" style="display: none;">
<Icon code="&#xf0c1;" />
</span>
<header>
<h1>{title}</h1>
<address>
<time datetime={date}>{date}</time>,
<a href="https://t.me/dcat09" rel="author">DarkCat09</a>
</address>
</header>
<article>
<postObj.Content />
</article>
</BlogLayout>
<style lang="less" is:global>
article {
//padding: 0 0.75rem;
& > h1:first-of-type {
display: none;
}
}
h1, h2, h3, h4, h5, h6 {
margin: 0;
}
.heading-link {
display: inline-block;
font-size: 1rem;
}
blockquote {
margin: 0;
padding: 0;
padding-left: 1.2rem;
border-left: 0.25rem solid var(--bg-sec);
}
pre {
padding: 1rem;
border-radius: var(--bdrs);
font-size: 1rem;
font-family: "JetBrains Mono", "Fira Code", "Iosevka", "Source Code Pro",
"Liberation Mono", "Lucida Console", monospace;
}
img {
display: block;
max-width: 90%;
margin: auto;
}
table {
max-width: 90%;
margin: auto;
border-collapse: collapse;
border-bottom: 0.125rem dashed var(--bg-sec);
th, td {
padding: 0.125rem 1rem;
}
th {
background: var(--bg-sec);
&:first-child {
border-top-left-radius: var(--bdrs);
border-bottom-left-radius: var(--bdrs);
}
&:last-child {
border-top-right-radius: var(--bdrs);
border-bottom-right-radius: var(--bdrs);
}
}
tbody > tr {
&:hover {
color: var(--accent-hl);
}
}
}
</style>
<script>
const linkIcon = document.getElementById("link-icon").innerHTML || "";
const hs = document.querySelectorAll("article h1,h2,h3");
for (let h of hs) {
const link = document.createElement("a");
link.classList.add("heading-link");
link.innerHTML = linkIcon;
link.href = "#" + h.id;
h.append(link);
}
</script>

View file

@ -0,0 +1,14 @@
---
import BlogLayout from "../../layouts/BlogLayout.astro";
const description =
"DarkCat09's blog about IT. " +
"Reading a QR code without smartphone, " +
"breaking a password on Windows, " +
"coding your own browser... " +
"The simpliest things!";
---
<BlogLayout title="Homepage" description={description}>
//
</BlogLayout>

View file

@ -0,0 +1,47 @@
---
import { getCollection } from "astro:content";
const posts = await getCollection('blog');
const encodedArray =
'["' + posts.map(post => post.slug).join('","') + '"]';
---
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<meta name="robots" content="noindex, nofollow" />
<meta id="posts" data-posts={encodedArray} />
<title>Random post</title>
</head>
<body>
<noscript>
"Random post" feature does not work without JavaScript
</noscript>
</body>
</html>
<style lang="less">
@import "/src/styles/theme.less";
body {
.theme-mixin();
background: var(--bg);
color: var(--fg);
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Liberation Sans', 'Helvetica Neue', sans-serif;
}
noscript {
font-size: 2rem;
}
</style>
<script>
const data = document.getElementById('posts').dataset.posts || "[]"
const arr: Array<string> = JSON.parse(data)
const rand = Math.floor(Math.random() * arr.length)
window.location.href = window.location.origin + '/blog/' + arr[rand]
</script>

View file

@ -0,0 +1,8 @@
---
import BlogLayout from "../../layouts/BlogLayout.astro";
import BlogSearch from "../../components/BlogSearch.astro";
---
<BlogLayout title="Search" description="Search through the blog">
<BlogSearch method={"get"} />
</BlogLayout>

View file

@ -0,0 +1,8 @@
---
import BlogLayout from "../../layouts/BlogLayout.astro";
import BlogSearch from "../../components/BlogSearch.astro";
---
<BlogLayout title="Blog | Search" description="Search through the blog">
<BlogSearch method={"post"} />
</BlogLayout>

View file

@ -0,0 +1,11 @@
---
import BlogLayout from "../../layouts/BlogLayout.astro";
const description =
"Short stories from my life " +
"on the topic of IT";
---
<BlogLayout title="Blog | Shorts" description={description}>
//
</BlogLayout>