Skip to content

Commit

Permalink
category casing
Browse files Browse the repository at this point in the history
  • Loading branch information
Reed Nelson committed Dec 6, 2023
1 parent 1deb3cf commit 8ead542
Show file tree
Hide file tree
Showing 31 changed files with 77 additions and 59 deletions.
2 changes: 1 addition & 1 deletion src/content/blog/crypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Cryptography
description: none
date: 2022-08-30T05:00:00Z
categories: [Cryptography]
categories: [computer-science]
author: Reed Nelson
tags: [cryptography]
complexity: 1
Expand Down
2 changes: 1 addition & 1 deletion src/content/blog/debruijn.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: De Bruijn Sequences
description: De Bruijn sequences make up a niche topic at an intersection of graph theory and combinatorics. We will discuss some of the properties of these sequences, and their surprising applications.
date: 2021-05-05T06:00:00Z
categories: [Mathematics]
categories: [mathematics]
author: Reed Nelson
tags: [math, graph]
complexity: 1.5
Expand Down
2 changes: 1 addition & 1 deletion src/content/blog/dh.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Diffie Hellman
description: none
date: 2022-07-10T05:00:00Z
categories: [Cryptography]
categories: [computer-science]
author: Reed Nelson
tags: [math, cryptography]
complexity: 1
Expand Down
2 changes: 1 addition & 1 deletion src/content/blog/dharma.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: A Theory on Dharma
description: Who are you meant to be? Is that who you are? How can you become that person? We discuss an actionable guide to answering these questions, which is based on the teachings of the Bhagavad Gita.
date: 2020-10-10T05:00:00Z
categories: [Philosophy]
categories: [philosophy]
author: Reed Nelson
tags: [dharma, purpose]
complexity: 1
Expand Down
2 changes: 1 addition & 1 deletion src/content/blog/huffman.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Huffman Compression
description: Data compression is a process of modifying the representation of some information so that it can be stored using less data. We discuss how information is quantified (entropy), and a simple, speedy, and greedy compression algorithm (the Huffman Coding).
date: 2022-06-30T05:00:00Z
categories: [Cryptography]
categories: [computer-science]
author: Reed Nelson
tags: [math, cryptography, information-theory]
complexity: 1.7
Expand Down
2 changes: 1 addition & 1 deletion src/content/blog/language.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Topics in Language and Meaning
description: This post is a crash course on the introductory topics in the Philosophy of Language and Meaning. If you're a natural language speaker, then in a sense, you're already an expert on these topics!
date: 2021-04-04T05:00:00Z
categories: [Philosophy]
categories: [philosophy]
author: Reed Nelson
tags: [language]
complexity: 1.2
Expand Down
2 changes: 1 addition & 1 deletion src/content/blog/love.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: The Psychology of Love
description: In this post, we discuss a General Theory of Love, which makes bold and uplifting claims about the power of the emotional mind. Whether or not the theory is completely true, there are valuable ideas to be gleaned.
date: 2020-02-14T05:00:00Z
categories: [Psychology]
categories: [uncategorized]
author: Reed Nelson
tags: [psychology, philosophy, love]
complexity: 1.1
Expand Down
2 changes: 1 addition & 1 deletion src/content/blog/microbiome.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Microbiome Network Alignment
description: none
date: 2022-08-15T05:00:00Z
categories: [Mathematics]
categories: [mathematics]
author: Reed Nelson
tags: [math, biology, graph]
complexity: 1
Expand Down
2 changes: 1 addition & 1 deletion src/content/blog/phenomenology.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Artificial Consciousness and Phenomenology
description: I believe that with a phenomenological examination of human consciousness and experience, we stand to better express what is necessary for a true, human-level artificial consciousness.
date: 2022-04-07T05:00:00Z
categories: [Philosophy]
categories: [philosophy]
author: Reed Nelson
tags: [ai]
complexity: 1.2
Expand Down
2 changes: 1 addition & 1 deletion src/content/blog/power.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: The Will to Power
description: Friedrich Nietzsche is one of the most significant philosophers of all time. Here we discuss Nietzsche's invigorating and liberating philosophy for living.
date: 2021-09-25T05:00:00Z
categories: [Philosophy]
categories: [philosophy]
author: Reed Nelson
tags: [purpose, power, nietzsche]
complexity: 1.1
Expand Down
2 changes: 1 addition & 1 deletion src/content/blog/rsa.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: RSA Encryption
description: You use the RSA encryption scheme every day. It's simple enough to understand, but quite powerful. In this post, we discuss the basics of ciphersystems, public key encryption, and why RSA works so well.
date: 2022-06-10T05:00:00Z
categories: [Cryptography]
categories: [computer-science]
author: Reed Nelson
tags: [math, cryptography]
complexity: 1.5
Expand Down
8 changes: 4 additions & 4 deletions src/layouts/BlogSingle.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import config from "@/config/config.json";
import { getSinglePage } from "@/lib/contentParser.astro";
import dateFormat from "@/lib/utils/dateFormat";
import similerItems from "@/lib/utils/similarItems";
import { humanize, markdownify, slugify } from "@/lib/utils/textConverter";
import { lowerHumanize, upperHumanize, markdownify, slugify } from "@/lib/utils/textConverter";
import {
FaRegCalendarAlt,
Expand All @@ -32,7 +32,7 @@ tags.sort((a: string, b: string) => a.localeCompare(b));
<ul class="mb-4">
<li class="mr-4 inline-block">
<FaRegUserCircle className={"mr-2 -mt-1 inline-block"} />
{humanize(author)}
{upperHumanize(author)}
</li>
<li class="mr-4 inline-block">
<FaRegCalendarAlt className={"mr-2 -mt-1 inline-block"} />
Expand All @@ -43,7 +43,7 @@ tags.sort((a: string, b: string) => a.localeCompare(b));
{
categories.map((category: string, index: number) => (
<a href={`/blog/categories/${slugify(category)}`}>
{humanize(category)}
{upperHumanize(category)}
{index !== categories.length - 1 && ","}
</a>
))
Expand All @@ -65,7 +65,7 @@ tags.sort((a: string, b: string) => a.localeCompare(b));
class="m-1 block rounded bg-theme-light px-3 py-1 hover:bg-primary hover:text-white dark:bg-darkmode-theme-light dark:hover:bg-darkmode-primary dark:hover:text-dark"
href={`/blog/tags/${slugify(tag)}`}
>
{tag}
{lowerHumanize(tag)}
</a>
</li>
))
Expand Down
8 changes: 4 additions & 4 deletions src/layouts/DrinkSingle.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Share from "@/components/Share.astro";
import config from "@/config/config.json";
import { getSinglePage } from "@/lib/contentParser.astro";
import similerItems from "@/lib/utils/similarItems";
import { markdownify } from "@/lib/utils/textConverter";
import { lowerHumanize, markdownify } from "@/lib/utils/textConverter";
import { Image } from "astro:assets";
interface Recipe {
Expand Down Expand Up @@ -65,7 +65,7 @@ const { ingredients, instructions, notes }: Recipe = post.data;
class="m-1 inline-block rounded bg-white px-3 py-1 hover:bg-primary hover:text-white dark:bg-darkmode-body dark:hover:bg-darkmode-primary dark:hover:text-dark"
href={`/drinks/spirits/${spirit}`}
>
{spirit}
{lowerHumanize(spirit)}
</a>
))}
</li>
Expand All @@ -82,7 +82,7 @@ const { ingredients, instructions, notes }: Recipe = post.data;
class="m-1 inline-block rounded bg-white px-3 py-1 hover:bg-primary hover:text-white dark:bg-darkmode-body dark:hover:bg-darkmode-primary dark:hover:text-dark"
href={`/drinks/bottles/${bottle}`}
>
{bottle}
{lowerHumanize(bottle)}
</a>
))}
</li>
Expand All @@ -98,7 +98,7 @@ const { ingredients, instructions, notes }: Recipe = post.data;
class="m-1 inline-block rounded bg-white px-3 py-1 hover:bg-primary hover:text-white dark:bg-darkmode-body dark:hover:bg-darkmode-primary dark:hover:text-dark"
href={`/drinks/tags/${tag}`}
>
{tag}
{lowerHumanize(tag)}
</a>
))}
</li>
Expand Down
4 changes: 2 additions & 2 deletions src/layouts/FoodSingle.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Share from "@/components/Share.astro";
import config from "@/config/config.json";
import { Image } from "astro:assets";
import { humanize, markdownify } from "@/lib/utils/textConverter";
import { upperHumanize, markdownify } from "@/lib/utils/textConverter";
import {
FaRegClock,
Expand Down Expand Up @@ -56,7 +56,7 @@ const { ingredients, instructions, notes }: Recipe = post.data;
{ author && (
<div class="m-4">
<FaRegUserCircle className={"mr-2 -mt-1 inline-block"} />
{humanize(author)}
{upperHumanize(author)}
</div>
)}
<!-- Prep Time -->
Expand Down
6 changes: 3 additions & 3 deletions src/layouts/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import config from "@/config/config.json";
import { humanize, plainify, slugify } from "@/lib/utils/textConverter";
import { upperHumanize, plainify, slugify } from "@/lib/utils/textConverter";
import Fuse from "fuse.js";
import React, { useEffect, useRef, useState } from "react";
import {
Expand Down Expand Up @@ -125,7 +125,7 @@ const Search = ({ searchList }: Props) => {
<FaRegUserCircle
className={"-mt-1 mr-2 inline-block"}
/>
{humanize(item.data.author)}
{upperHumanize(item.data.author)}
</li>
<li className="mr-4 inline-block">
<FaRegFolder className={"-mt-1 mr-2 inline-block"} />
Expand All @@ -135,7 +135,7 @@ const Search = ({ searchList }: Props) => {
href={`/blog/categories/${slugify(category)}`}
key={category}
>
{humanize(category)}
{upperHumanize(category)}
{index !== item.data.categories.length - 1 && ", "}
</a>
),
Expand Down
4 changes: 2 additions & 2 deletions src/layouts/components/BlogCard.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
import config from "@/config/config.json";
import { humanize, slugify } from "@/lib/utils/textConverter";
import { upperHumanize, slugify } from "@/lib/utils/textConverter";
import { FaRegFolder, FaRegClock } from "react-icons/fa/index.js";
import readingTime from "@/lib/utils/readingTime";
Expand All @@ -24,7 +24,7 @@ const { title, description, categories, complexity } = data.data;
{
categories.map((category: string, index: number) => (
<a href={`/blog/categories/${slugify(category)}`}>
{humanize(category)}
{upperHumanize(category)}
{index !== categories.length - 1 && ","}
</a>
))
Expand Down
6 changes: 3 additions & 3 deletions src/layouts/components/BlogSidebar.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import { humanize } from "@/lib/utils/textConverter";
import { lowerHumanize, upperHumanize } from "@/lib/utils/textConverter";
const { tags, categories, allCategories } = Astro.props;
---
Expand All @@ -23,7 +23,7 @@ const { tags, categories, allCategories } = Astro.props;
class="flex justify-between hover:text-primary dark:hover:text-darkmode-primary"
href={`/blog/categories/${category}`}
>
{humanize(category)} <span>({count})</span>
{upperHumanize(category)} <span>({count})</span>
</a>
</li>
);
Expand All @@ -47,7 +47,7 @@ const { tags, categories, allCategories } = Astro.props;
class="m-1 block rounded bg-white px-3 py-1 hover:bg-primary hover:text-white dark:bg-darkmode-body dark:hover:bg-darkmode-primary dark:hover:text-dark"
href={`/blog/tags/${tag}`}
>
{tag}
{lowerHumanize(tag)}
</a>
</li>
);
Expand Down
7 changes: 4 additions & 3 deletions src/layouts/components/Breadcrumbs.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
import { lowerHumanize } from "@/lib/utils/textConverter";
const { className }: { className?: string } = Astro.props;
const paths = Astro.url.pathname.split("/").filter((x) => x);
Expand All @@ -14,7 +15,7 @@ paths.forEach((label: string, i: number) => {
const href = `/${paths.slice(0, i + 1).join("/")}`;
label !== "page" &&
parts.push({
label: label.replace(/[-_]/g, " ") || "",
label: label,
href,
"aria-label": Astro.url.pathname === href ? "page" : undefined,
});
Expand All @@ -29,10 +30,10 @@ paths.forEach((label: string, i: number) => {
{index > 0 && <span class="inlin-block mr-1">/</span>}
{index !== parts.length - 1 ? (
<a class="text-primary dark:text-darkmode-primary" {...attrs}>
{label}
{lowerHumanize(label)}
</a>
) : (
<span class="text-light dark:text-darkmode-light">{label}</span>
<span class="text-light dark:text-darkmode-light">{lowerHumanize(label)}</span>
)}
</li>
))
Expand Down
7 changes: 4 additions & 3 deletions src/layouts/components/DrinkSidebar.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
import { lowerHumanize } from "@/lib/utils/textConverter";
const { tags, spirits, bottles, allSpirits, allBottles } = Astro.props;
---

Expand All @@ -18,7 +19,7 @@ const { tags, spirits, bottles, allSpirits, allBottles } = Astro.props;
class="m-1 block rounded bg-white px-3 py-1 hover:bg-primary hover:text-white dark:bg-darkmode-body dark:hover:bg-darkmode-primary dark:hover:text-dark"
href={`/drinks/spirits/${spirit}`}
>
{spirit}
{lowerHumanize(spirit)}
</a>
</li>
);
Expand All @@ -39,7 +40,7 @@ const { tags, spirits, bottles, allSpirits, allBottles } = Astro.props;
class="m-1 block rounded bg-white px-3 py-1 hover:bg-primary hover:text-white dark:bg-darkmode-body dark:hover:bg-darkmode-primary dark:hover:text-dark"
href={`/drinks/bottles/${bottle}`}
>
{bottle}
{lowerHumanize(bottle)}
</a>
</li>
);
Expand All @@ -60,7 +61,7 @@ const { tags, spirits, bottles, allSpirits, allBottles } = Astro.props;
class="m-1 block rounded bg-white px-3 py-1 hover:bg-primary hover:text-white dark:bg-darkmode-body dark:hover:bg-darkmode-primary dark:hover:text-dark"
href={`/drinks/tags/${tag}`}
>
{tag}
{lowerHumanize(tag)}
</a>
</li>
);
Expand Down
3 changes: 2 additions & 1 deletion src/layouts/components/PageHeader.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
import Breadcrumbs from "@/components/Breadcrumbs.astro";
import { upperHumanize } from "@/lib/utils/textConverter";
const { title = "" }: { title?: string } = Astro.props;
---
Expand All @@ -9,7 +10,7 @@ const { title = "" }: { title?: string } = Astro.props;
<div
class="rounded-2xl bg-gradient-to-b from-body to-theme-light px-8 py-14 dark:from-darkmode-body dark:to-darkmode-theme-light"
>
<h1 set:text={title} />
<h1 set:text={upperHumanize(title)} />
<Breadcrumbs className="mt-6" />
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/layouts/shortcodes/Notice.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { humanize } from "@/lib/utils/textConverter";
import { upperHumanize } from "@/lib/utils/textConverter";
import React from "react";

function Notice({
Expand Down Expand Up @@ -75,7 +75,7 @@ function Notice({
/>
</svg>
)}
<p className="my-0 ml-1.5">{humanize(type)}</p>
<p className="my-0 ml-1.5">{upperHumanize(type)}</p>
</div>
<div className="notice-body">{children}</div>
</div>
Expand Down
19 changes: 12 additions & 7 deletions src/lib/utils/textConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@ export const markdownify = (content: string, div?: boolean) => {
return div ? marked.parse(content) : marked.parseInline(content);
};

// humanize
export const humanize = (content: string) => {
// hyphen to space, uppercase only first letter in each word
export const upperHumanize = (content: string) => {
return content
.replace(/^[\s_]+|[\s_]+$/g, "")
.replace(/[_\s]+/g, " ")
.replace(/^[a-z]/, function (m) {
return m.toUpperCase();
});
.toLowerCase()
.replace(/-/g, " ")
.replace(/(^\w{1})|(\s{1}\w{1})/g, (match) => match.toUpperCase());
};

// hyphen to space, lowercase all letters
export const lowerHumanize = (content: string) => {
return content
.toLowerCase()
.replace(/-/g, " ");
};

// plainify
Expand Down
4 changes: 2 additions & 2 deletions src/pages/blog/categories/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import config from "@/config/config.json";
import Base from "@/layouts/Base.astro";
import { getAllTaxonomy, getTaxonomy } from "@/lib/taxonomyParser.astro";
import { humanize } from "@/lib/utils/textConverter";
import { upperHumanize } from "@/lib/utils/textConverter";
import PageHeader from "@/components/PageHeader.astro";
const { blog_folder }: { blog_folder: string } = config.settings;
Expand All @@ -24,7 +24,7 @@ const allCategories = await getAllTaxonomy(blog_folder, "categories");
href={`/blog/categories/${category}`}
class="block rounded bg-theme-light px-4 py-2 text-xl text-dark dark:bg-darkmode-theme-light dark:text-darkmode-dark"
>
{humanize(category)}{" "}
{upperHumanize(category)}{" "}
<span class="ml-2 rounded bg-body px-2 dark:bg-darkmode-body">
{count}
</span>
Expand Down
Loading

0 comments on commit 8ead542

Please sign in to comment.