Skip to content

Commit

Permalink
complexity coefficient
Browse files Browse the repository at this point in the history
  • Loading branch information
Reed Nelson committed Aug 13, 2023
1 parent 76c2eb6 commit 2c8504c
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/content/blog/crypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ image: ""
categories: ["Cryptography"]
author: "Reed Nelson"
tags: ["crypto"]
complexity: 1
draft: true
---

Expand Down
1 change: 1 addition & 0 deletions src/content/blog/debruijn.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ image: ""
categories: ["Mathematics"]
author: "Reed Nelson"
tags: ["math", "graph"]
complexity: 1.5
draft: false
---

Expand Down
1 change: 1 addition & 0 deletions src/content/blog/dh.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ image: ""
categories: ["Cryptography"]
author: "Reed Nelson"
tags: ["math", "crypto"]
complexity: 1
draft: true
---

Expand Down
1 change: 1 addition & 0 deletions src/content/blog/dharma.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ image: ""
categories: ["Philosophy"]
author: "Reed Nelson"
tags: ["dharma", "purpose"]
complexity: 1
draft: false
---

Expand Down
1 change: 1 addition & 0 deletions src/content/blog/ent.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ image: ""
categories: ["Mathematics"]
author: "Reed Nelson"
tags: ["math", "puzzles"]
complexity: 0
draft: true
---

Expand Down
1 change: 1 addition & 0 deletions src/content/blog/huffman.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ image: ""
categories: ["Cryptography"]
author: "Reed Nelson"
tags: ["math", "crypto", "information-theory"]
complexity: 1.7
draft: false
---

Expand Down
1 change: 1 addition & 0 deletions src/content/blog/language.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ image: ""
categories: ["Philosophy"]
author: "Reed Nelson"
tags: ["language"]
complexity: 1.2
draft: false
---

Expand Down
1 change: 1 addition & 0 deletions src/content/blog/love.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ image: ""
categories: ["Psychology"]
author: "Reed Nelson"
tags: ["psychology", "philosophy", "love"]
complexity: 1.1
draft: false
---

Expand Down
1 change: 1 addition & 0 deletions src/content/blog/microbiome.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ image: ""
categories: ["Mathematics"]
author: "Reed Nelson"
tags: ["math", "biology", "graph"]
complexity: 1
draft: true
---

Expand Down
1 change: 1 addition & 0 deletions src/content/blog/phenomenology.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ image: ""
categories: ["Philosophy"]
author: "Reed Nelson"
tags: ["ai"]
complexity: 1.2
draft: false
---

Expand Down
1 change: 1 addition & 0 deletions src/content/blog/power.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ image: ""
categories: ["Philosophy"]
author: "Reed Nelson"
tags: ["purpose", "power", "nietzsche"]
complexity: 1.1
draft: false
---

Expand Down
1 change: 1 addition & 0 deletions src/content/blog/rsa.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ image: ""
categories: ["Cryptography"]
author: "Reed Nelson"
tags: ["math", "crypto"]
complexity: 1.5
draft: false
---

Expand Down
3 changes: 2 additions & 1 deletion src/content/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ const blogCollection = defineCollection({
description: z.string().optional(),
date: z.date().optional(),
image: z.string().optional(),
author: z.string().default("Admin"),
author: z.string().default("Reed Nelson"),
categories: z.array(z.string()).default(["others"]),
tags: z.array(z.string()).default(["others"]),
complexity: z.number().default(1),
draft: z.boolean().optional(),
}),
});
Expand Down
10 changes: 3 additions & 7 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, plainify, slugify } from "@/lib/utils/textConverter";
import { humanize, slugify } from "@/lib/utils/textConverter";
import { Image } from "@astrojs/image/components";
import { FaRegFolder, FaRegClock } from "react-icons/fa/index.js";
import readingTime from "@/lib/utils/readingTime";
Expand All @@ -10,7 +10,7 @@ const {
blog_folder,
}: { summary_length: number; blog_folder: string } = config.settings;
const { data } = Astro.props;
const { title, image, description, author, categories } = data.data;
const { title, image, description, categories, complexity } = data.data;
---

<div class="bg-body dark:bg-darkmode-body">
Expand All @@ -32,10 +32,6 @@ const { title, image, description, author, categories } = data.data;
</a>
</h4>
<ul class="mb-4">
<!-- <li class="mr-4 inline-block">
<FaRegUserCircle className={"mr-2 -mt-1 inline-block"} />
{humanize(author)}
</li> -->
<li class="mr-4 inline-block">
<FaRegFolder className={"mr-1 -mt-1 inline-block"} />
{
Expand All @@ -49,7 +45,7 @@ const { title, image, description, author, categories } = data.data;
</li>
<li class="mr-4 inline-block ">
<FaRegClock className={"mr-1 -mt-1 inline-block"} />
{readingTime(data.body)}
{readingTime(data.body, complexity)}
</li>
</ul>
<!-- <p class="mb-6">{plainify(data.body?.slice(0, Number(summary_length)))}</p> -->
Expand Down
22 changes: 15 additions & 7 deletions src/lib/utils/readingTime.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
// content reading
const readingTime = (content: string): string => {
const readingTime = (content: string, complexity: number): string => {
const WPS = 200 / 60;

let images = 0;
const regex = /\w/;

let words = content.split(" ").filter((word) => {
if (word.includes("<img")) {
if (word.includes(".png)")
|| word.includes(".jpg)")
|| word.includes(".svg)")
|| word.includes(".webp)")
|| word.includes(".gif)" )
) {
images += 1;
}
return regex.test(word);
}).length;

let imageAdjust = images * 4;
let imageSecs = 0;
let imageFactor = 12;

Expand All @@ -24,12 +28,16 @@ const readingTime = (content: string): string => {
images -= 1;
}

const minutes = Math.ceil(((words - imageAdjust) / WPS + imageSecs) / 60);
let ttr = 0; // time to read (in minutes)
ttr = words / WPS;
ttr = ttr + imageSecs;
ttr = ttr * complexity;
ttr = Math.ceil(ttr / 60);

if (minutes < 2) {
return minutes + ` min`;
if (ttr < 2) {
return ttr + ` min`;
} else {
return minutes + ` mins`;
return ttr + ` mins`;
}
};

Expand Down

0 comments on commit 2c8504c

Please sign in to comment.