mirror of
https://github.com/jbranchaud/til
synced 2026-01-21 07:58:02 +00:00
Compare commits
2 Commits
e5a003dbaf
...
028b76ba6b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
028b76ba6b | ||
|
|
1934c8f63e |
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
|||||||
|
|
||||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||||
|
|
||||||
_1464 TILs and counting..._
|
_1466 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -101,6 +101,7 @@ _1464 TILs and counting..._
|
|||||||
|
|
||||||
### Astro
|
### Astro
|
||||||
|
|
||||||
|
- [Generate Types For A Content Collection](astro/generate-types-for-a-content-collection.md)
|
||||||
- [Markdown Files Are Of Type MarkdownInstance](astro/markdown-files-are-of-type-markdown-instance.md)
|
- [Markdown Files Are Of Type MarkdownInstance](astro/markdown-files-are-of-type-markdown-instance.md)
|
||||||
|
|
||||||
### Brew
|
### Brew
|
||||||
@@ -1453,6 +1454,7 @@ _1464 TILs and counting..._
|
|||||||
- [List The Stack Of Remembered Directories](unix/list-the-stack-of-remembered-directories.md)
|
- [List The Stack Of Remembered Directories](unix/list-the-stack-of-remembered-directories.md)
|
||||||
- [Load Env Vars In Bash Script](unix/load-env-vars-in-bash-script.md)
|
- [Load Env Vars In Bash Script](unix/load-env-vars-in-bash-script.md)
|
||||||
- [Look Through All Files That Have Been Git Stashed](unix/look-through-all-files-that-have-been-git-stashed.md)
|
- [Look Through All Files That Have Been Git Stashed](unix/look-through-all-files-that-have-been-git-stashed.md)
|
||||||
|
- [Make Direnv Less Noisy](unix/make-direnv-less-noisy.md)
|
||||||
- [Map A Domain To localhost](unix/map-a-domain-to-localhost.md)
|
- [Map A Domain To localhost](unix/map-a-domain-to-localhost.md)
|
||||||
- [Negative Look-Ahead Search With ripgrep](unix/negative-look-ahead-search-with-ripgrep.md)
|
- [Negative Look-Ahead Search With ripgrep](unix/negative-look-ahead-search-with-ripgrep.md)
|
||||||
- [Occupy A Local Port With Netcat](unix/occupy-a-local-port-with-netcat.md)
|
- [Occupy A Local Port With Netcat](unix/occupy-a-local-port-with-netcat.md)
|
||||||
|
|||||||
56
astro/generate-types-for-a-content-collection.md
Normal file
56
astro/generate-types-for-a-content-collection.md
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
# Generate Types For A Content Collection
|
||||||
|
|
||||||
|
Let's say I'm using Astro to publish posts via markdown. One of the best ways
|
||||||
|
to do that is as a _Content Collection_. The posts will live in `src/content`
|
||||||
|
probably under a `posts` directory. Plus a config file will define the
|
||||||
|
collection and specify validations for the frontmatter.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// src/content/config.ts
|
||||||
|
import { defineCollection, z } from 'astro:content';
|
||||||
|
|
||||||
|
const postsCollection = defineCollection({
|
||||||
|
schema: z.object({
|
||||||
|
title: z.string(),
|
||||||
|
description: z.string(),
|
||||||
|
tags: z.array(z.string())
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
export const collections = {
|
||||||
|
'posts': postsCollection,
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
When I first add this to my project and get the collection, it won't know what
|
||||||
|
the types are.
|
||||||
|
|
||||||
|
```astro
|
||||||
|
---
|
||||||
|
import { getCollection } from "astro:content";
|
||||||
|
|
||||||
|
export async function getStaticPaths() {
|
||||||
|
const blogEntries = await getCollection("posts");
|
||||||
|
// ^^^ any
|
||||||
|
|
||||||
|
return blogEntries.map((entry) => ({
|
||||||
|
params: { slug: entry.slug },
|
||||||
|
props: { entry },
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
---
|
||||||
|
```
|
||||||
|
|
||||||
|
I can tell Astro to generate a fresh set of types for things like content
|
||||||
|
collections by running the [`astro sync`
|
||||||
|
command](https://docs.astro.build/en/reference/cli-reference/#astro-sync).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ npm run astro sync
|
||||||
|
```
|
||||||
|
|
||||||
|
This updates auto-generated files under the `.astro` directory which get pulled
|
||||||
|
in to your project's `env.d.ts` file.
|
||||||
|
|
||||||
|
All of these types will also be synced anytime I run `astro dev`, `astro
|
||||||
|
build`, or `astro check`.
|
||||||
32
unix/make-direnv-less-noisy.md
Normal file
32
unix/make-direnv-less-noisy.md
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# Make Direnv Less Noisy
|
||||||
|
|
||||||
|
I've been using [`direnv`](https://direnv.net/) to manage project and folder
|
||||||
|
specific environment variables for a bit now. I've found it to be pretty
|
||||||
|
seamless. It can feel like it is littering my shell with too much output when I
|
||||||
|
change directories though.
|
||||||
|
|
||||||
|
There are two levers to control its output.
|
||||||
|
|
||||||
|
First, the direnv logs (e.g. `direnv: loading ~/.../.envrc`) can be controlled
|
||||||
|
with the `DIRENV_LOG_FORMAT` env var. Add this to the
|
||||||
|
`~/.config/direnv/direnvrc` file (add that directory and file if necessary).
|
||||||
|
You can leave it blank to altogether hide log messages or you can gray-out the
|
||||||
|
log messages like this:
|
||||||
|
|
||||||
|
```
|
||||||
|
export DIRENV_LOG_FORMAT=$'\033[2mdirenv: %s\033[0m'
|
||||||
|
```
|
||||||
|
|
||||||
|
Second, you can hide the env var diff with a separate config. This diff is not
|
||||||
|
covered under the umbrella of logs controlled by the above setting. Set
|
||||||
|
[`hide_env_diff` in the `~/.config/direnv/direnv.toml`
|
||||||
|
file](https://direnv.net/man/direnv.toml.1.html#codehideenvdiffcode):
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[global]
|
||||||
|
hide_env_diff = true
|
||||||
|
```
|
||||||
|
|
||||||
|
This second config was only added as of `v2.34.0`.
|
||||||
|
|
||||||
|
[source](https://esham.io/2023/10/direnv)
|
||||||
Reference in New Issue
Block a user