davideisinger.com

My personal website
Log | Files | Refs | README

commit 40878393206594069db7ef6291b9714855f7692a
parent 48230935e7b38aa266b632a9a82d209a9e1848cf
Author: David Eisinger <[email protected]>
Date:   Wed, 20 Nov 2024 16:19:47 -0500

spelling post progress

Diffstat:
Mcontent/journal/spellcheck-your-hugo-site-with-cspell/index.md | 132++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 110 insertions(+), 22 deletions(-)

diff --git a/content/journal/spellcheck-your-hugo-site-with-cspell/index.md b/content/journal/spellcheck-your-hugo-site-with-cspell/index.md @@ -8,30 +8,130 @@ tags: Bla bla bla +[5]: https://cspell.org/ + <!--more--> ### 1. Install CSpell +Assuming a modern version of Node.js (>= 18), you can use [npx][1] to download and run CSpell in a single command: + +```sh +npx cspell content/**/*.md +``` + +You'll see a ton of spelling errors -- ignore them for now. + +[1]: https://docs.npmjs.com/cli/v10/commands/npx + ### 2. Add config file -### 3. Ignore frontmatter +Next, let's create a basic config file. In the root of your site, put the following in `.cspell.json`: + +```json +{ + "$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json", + "version": "0.2", + "dictionaries": [ + "english" + ] +} +``` + +### 3. Add additional languages + +My site (especially the stuff in [/elsewhere][2] that I've mirrored from my company's website) has code snippets that the English dictionary doesn't recognize. Fortunately, CSpell ships with a bunch of [additional dictionaries][3]. Adding `"ruby"`, `"golang"`, and `"java"` to the `"dictionaries"` array makes a bunch of misspellings go away. + +[2]: /elsewhere +[3]: https://github.com/streetsidesoftware/cspell-dicts/tree/main/dictionaries + +### 4. Ignore front matter + +```json +"patterns": [ + { + "name": "frontmatter", + "pattern": "/^(-{3}|[+]{3})$(\\s|\\S)*?^\\1$/gm" + } +], +"languageSettings": [ + { + "languageId": "markdown", + "ignoreRegExpList": [ + "frontmatter", + ] + } +] +``` + +[6]: https://gohugo.io/content-management/front-matter/ +[7]: https://github.com/streetsidesoftware/cspell/discussions/3456#discussioncomment-3438647 + +### 5. Ignore proper nouns + +```json +{ + "name": "proper_nouns", + "pattern": "/[\\W_][A-Z][\\S]+/g" +} +``` + +```json +"languageSettings": [ + { + "languageId": "markdown", + "ignoreRegExpList": [ + "frontmatter", + "proper_nouns" + ] + } +] +``` + +### 6. Fix spelling + +### 7. Create custom dictionary + +```sh +npx cspell --words-only --unique content/**/*.md >> .dictionary +``` -### 4. Ignore proper nouns +```json +"dictionaryDefinitions": [ + { + "name": "exceptions", + "path": ".dictionary", + "addWords": true + } +], +``` + +```json +"dictionaries": [ + "english", + "ruby", + "golang", + "exceptions" +] +``` + +```sh +npx cspell --words-only --unique content/**/*.md >> .dictionary +sort -o .dictionary .dictionary +``` -### 5. Fix spelling -### 6. Create custom dictionary +### 8. Add to build pipeline -### 7. Add to build pipeline +[8]: https://git.sr.ht/~dce/davideisinger.com/tree/main/item/.build.yml#L23-24 --- -[Here's the final `.cspell.json` config file.][1] +[Here's the final `.cspell.json` config file.][4] -[1]: https://git.sr.ht/~dce/davideisinger.com/tree/main/item/.cspell.json -[2]: https://cspell.org/ -[3]: https://github.com/streetsidesoftware/cspell/discussions/3456#discussioncomment-3438647 -[4]: https://git.sr.ht/~dce/davideisinger.com/tree/main/item/.build.yml#L23-24 +[4]: https://git.sr.ht/~dce/davideisinger.com/tree/main/item/.cspell.json + +--- ```json { @@ -71,15 +171,3 @@ Bla bla bla ] } ``` - -```sh -npx cspell content/**/*.md -``` - -```sh -npx cspell --words-only --unique content/**/*.md >> .dictionary -``` - -```sh -sort -o .dictionary .dictionary -```