From 7dc8e5c7be4b61cae360f0d232afc23feb4ecf84 Mon Sep 17 00:00:00 2001 From: Reed Nelson Date: Wed, 6 Sep 2023 15:02:04 -0500 Subject: [PATCH] puzzle --- src/config/config.json | 2 + src/config/menu.json | 4 + src/content/config.ts | 13 + src/content/puzzle/-index.md | 5 + src/content/puzzle/conventional-riddles.md | 233 ++++++++++++++++++ src/content/puzzle/example-riddles.md | 75 ++++++ src/content/puzzle/low-grade-riddles.md | 64 +++++ .../{blog/ent.md => puzzle/number-theory.md} | 3 - .../{riddles/-index.mdx => puzzle/riddles.md} | 4 + src/content/puzzle/situation-riddles.md | 91 +++++++ src/layouts/PuzzleSingle.astro | 52 ++++ src/layouts/components/PuzzleCard.astro | 26 ++ src/pages/puzzle/[single].astro | 29 +++ src/pages/puzzle/index.astro | 57 +++++ src/pages/puzzle/page/[slug].astro | 76 ++++++ src/pages/riddles.astro | 27 -- 16 files changed, 731 insertions(+), 30 deletions(-) create mode 100644 src/content/puzzle/-index.md create mode 100644 src/content/puzzle/conventional-riddles.md create mode 100644 src/content/puzzle/example-riddles.md create mode 100644 src/content/puzzle/low-grade-riddles.md rename src/content/{blog/ent.md => puzzle/number-theory.md} (99%) rename src/content/{riddles/-index.mdx => puzzle/riddles.md} (99%) create mode 100644 src/content/puzzle/situation-riddles.md create mode 100644 src/layouts/PuzzleSingle.astro create mode 100644 src/layouts/components/PuzzleCard.astro create mode 100644 src/pages/puzzle/[single].astro create mode 100644 src/pages/puzzle/index.astro create mode 100644 src/pages/puzzle/page/[slug].astro delete mode 100644 src/pages/riddles.astro diff --git a/src/config/config.json b/src/config/config.json index d859554..dedc68e 100755 --- a/src/config/config.json +++ b/src/config/config.json @@ -14,8 +14,10 @@ "default_theme": "system", "blog_pagination": 4, "drink_pagination": 6, + "puzzle_pagination": 6, "summary_length": 200, "blog_folder": "blog", + "puzzle_folder": "puzzle", "drink_folder": "drink" }, diff --git a/src/config/menu.json b/src/config/menu.json index e0289d3..6c6146a 100755 --- a/src/config/menu.json +++ b/src/config/menu.json @@ -16,6 +16,10 @@ "name": "Blog", "url": "/blog" }, + { + "name": "Puzzles", + "url": "/puzzle" + }, { "name": "Drinks", "url": "/drink" diff --git a/src/content/config.ts b/src/content/config.ts index 8cd2da1..657e5f9 100755 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -15,6 +15,18 @@ const blogCollection = defineCollection({ }), }); +// Puzzle collection schema +const puzzleCollection = defineCollection({ + schema: z.object({ + title: z.string(), + meta_title: z.string().optional(), + description: z.string().optional(), + date: z.date().optional(), + author: z.string().default("Reed Nelson"), + draft: z.boolean().optional(), + }), +}); + // Drink collection schema const drinkCollection = defineCollection({ schema: z.object({ @@ -39,5 +51,6 @@ const drinkCollection = defineCollection({ // Export collections export const collections = { blog: blogCollection, + puzzle: puzzleCollection, drink: drinkCollection, }; diff --git a/src/content/puzzle/-index.md b/src/content/puzzle/-index.md new file mode 100644 index 0000000..5c37575 --- /dev/null +++ b/src/content/puzzle/-index.md @@ -0,0 +1,5 @@ +--- +title: Puzzles +meta_title: Puzzles +description: A selection of good puzzles. +--- diff --git a/src/content/puzzle/conventional-riddles.md b/src/content/puzzle/conventional-riddles.md new file mode 100644 index 0000000..8243615 --- /dev/null +++ b/src/content/puzzle/conventional-riddles.md @@ -0,0 +1,233 @@ +--- +title: Riddles +meta_title: Riddles +description: It's Riddles. +date: 2023-09-01T05:00:00Z +author: Reed Nelson +draft: true +--- + +
+Table of Contents + +- [The Impossible Chessboard Problem](#the-impossible-chessboard-problem) +- [The Sum and Product Puzzle](#the-sum-and-product-puzzle) +- [Two Guards](#two-guards) +- [Cheryl’s Birthday](#cheryls-birthday) +- [The Gold Scale](#the-gold-scale) +- [Billiard Balls](#billiard-balls) +- [Spot the Dog](#spot-the-dog) +- [Two Ropes](#two-ropes) +- [Hard Boiled](#hard-boiled) +- [The Great Divide](#the-great-divide) +- [Mutilated Chessboard Problem](#mutilated-chessboard-problem) +- [Reservior Golfers](#reservior-golfers) +- [Very Contrived Situation](#very-contrived-situation) +- [Island Fire](#island-fire) +- [The Emperor's New Game](#the-emperors-new-game) +- [The Overtold Funeral Riddle](#the-overtold-funeral-riddle) + +
+ +## The Impossible Chessboard Problem + +The jailer will take you into a private cell. In the cell will be a chessboard and a jar containing 64 coins. +The jailer will take the coins, one-by-one, and place a coin on each square on the board. He will place the coins randomly on the board. Some coins will be heads, and some tails (or maybe they will be all heads, or all tails; you have no idea. It's all at the jailers whim. He may elect to look and choose to make a pattern himself, he may toss them placing them the way they land, he might look at them as he places them, he might not …). All you can do it watch. +Once all the coins have been laid out, the jailer will point to one of the squares on the board, indicating the one with the key under it (invisible from your position). The jailer will then allow you to turn over any one coin on the board. This is the only change you are allowed to make to the jailers initial layout. +You will then be lead out of the room, and the jailer will bring in your friend, who will examine the board of coins and decide under which square the key is. They have only one chance to guess correctly, in which case you’re both set free. +The jailer explains all these rules, to both you and your friend, beforehand and then gives you time to confer with each other to devise a strategy for which coin to flip. + +
+ Solution + ??? +
+ +Solution: + +## The Sum and Product Puzzle + +X and Y are two different whole numbers greater than 1. Their sum is not greater than 100, and Y is greater than X. S and P are two mathematicians (and perfect logicians); S knows the sum X + Y, and P knows the product X * Y. Both S and P know all the information in this paragraph. +The following conversation occurs: +S says “P does not know X and Y” +P says “Now I know X and Y” +S says “Now I also know X and Y” +What are X and Y? + +
+ Solution + ??? +
+ +## Two Guards + +There are two paths forward, one will lead you where you want to go, the other will lead you to certain death. In front of each path stands a guard, one always lies, and the other always tells the truth. You don't know which guard is which, nor which path is which. In one question, what can you ask one of the guards to find out which path will where you where you wish to go? + +
+ Solution + Ask the guard "If I asked the other guard which path they guard, what would they say?" +
+ +## Cheryl’s Birthday + +Albert and Bernard just become friends with Cheryl, and they want to know when her birthday is. Cheryl gives them a list of 10 possible dates: + +| May | June | July | August | +|--------|--------|--------|--------| +| | | 14 | 14 | +| 15 | | | 15 | +| 16 | | 16 | | +| | 17 | | 17 | +| | 18 | | | +| 19 | | | | + +Cheryl then tells Albert and Bernard separately the month and the day of her birthday respectively. +Albert: I don't know when Cheryl's birthday is, but I know that Bernard doesn't know too. +Bernard: At first I don't know when Cheryl's birthday is, but I know now. +Albert: Then I also know when Cheryl's birthday is. +So when is Cheryl's birthday? + +
+ Solution + When Albert says his first line, it tells Bernard that the month is not May or June. These are the only months with a unique number, so for Albert to know Bernard doesn’t know right off the bat, it must be the case that Albert knows it’t in neither of those months. We know that narrowing it down to that extent is sufficient for Bernard to determine the birthday, which tells Albert it couldn’t have been the 14th. That information is sufficient for Albert to determine the birthday, because Albert knows the month. It would not be sufficient if the month was August. [It’s July 16th] +
+ +## The Gold Scale + +There are 100 bags each with 100 coins, but only one of these bags has gold coins in it. The gold coin has weight of 1.01 grams and the other coins has weight of 1 gram. We are given a digital scale, but we can only use it once. How can we identify the bag of gold coins? + +
+ Solution + Give the bags numbers from 0 through 99, then take 0 coins from the bag number 0, 1 coin from the bag number 1, 2 coins from the bag number 2, and so on until we take 99 coins from the bag number 99. Gather all the coins we have taken together and put them on the scale. Use a triangle to easily calculate your expected weight sum should all the coins be fake, then .howevermanygrams over that value you are is how many pieces you put on the scale from that bag. +
+ +## Billiard Balls + +This one’s a wee bit ridiculous You have 12 billiard balls, one is heavier or lighter than the rest. You can use a justice-y scale up to 3 times to determine which ball is the odd one, and whether it’s heavier or lighter. + +
+ Solution + The strat for the first weigh is to do 4&4, if they’re equal then you’ve narrowed it down to 4 and it’s trivial, if not equal, keep track of which are (possibly) heavier and lighter. For the second weigh put 2 of the lighter and 1 of the 4 you didn’t weigh (but know must be normal) on one side, and the other 2 lighter and a heavier on the other side. From there there’s a couple possibilities but with the knowledge you get from the first 2 weighs the options for the 3rd weigh become trivial ish. (For the 2nd, they obviously don’t have to be the lighter balls, just have to use 2 on each side of the balls that were on the same side for the 1st weigh, and note whether they’re heavier or lighter). +
+ +## Spot the Dog + +Spot is a dog. Every dog has one alpha (also a dog), and no two dogs have the same alpha. But Spot isn't anybody's alpha. :( +For any two dogs, there is an assigned referee in case they get into a fight and an assigned marriage counselor in case they get married. The dogs have set up the following rules for deciding who will be the referees and counselors for who: +If Spot fights with any dog, the other dog gets to be the referee. The referee of a fight between (dog 1) and (dog 2’s alpha) has to be the alpha of the referee of a fight between dogs 1 and 2. +Spot has to be his own marriage counselor, no matter who he marries. The marriage counselor for (dog 1) and (dog 2’s alpha) has to referee any fight between dog 1 and the marriage counselor for dog 1 and dog 2. +Who’s the marriage counselor for Spot’s alpha and the referee of a fight between Spot’s alpha and himself (Spot’s alpha)? + +
+ Solution + Spot’s Alpha’s Alpha. +
+ +## Two Ropes + +You have two ropes, each of which will burn at varying speeds throughout their lengths, but by the end have burned for exactly 1 hour. How can you measure 45 minutes? + +
+ Solution + Burn rope A at both ends and rope B at one. As soon as A is completely gone, light the other end of rope B. +
+ +## Hard Boiled + +You have a 7-minute hourglass and an 11-minute hourglass, how can you boil an egg in exactly 15 minutes? + +
+ Solution + Start both hourglasses as you start boiling the egg. After the 7-minute hourglass runs out, turn it to start it again. Four minutes later, when the 11-minute hourglass runs out, turn the 7-minute hourglass again. Wait for the 7-minute hourglass to run out, which will take another four minutes and get you to exactly 15 minutes of boiling time. +
+ +## The Great Divide + +Four people arrive at a river with a narrow bridge that can only hold two people at a time. It's nighttime and they have one torch that has to be used when crossing the bridge. Person A can cross the bridge in one minute, B in two minutes, C in five minutes, and D in eight minutes. When two people cross the bridge together, they must move at the slower person's pace. Can they all get across the bridge in 15 minutes or less? + +
+ Solution + Yes, 15: 1&2, 1, 5&8, 2, 1&2 +
+ +Riddle: Dice +Solution: same + +
+ Solution + +
+ +## Mutilated Chessboard Problem + +Two tiles, each from opposite corners of a chess board, are removed from the board. Is it possible for 31 dominoes, each covering 2 full tiles, to completely cover the remaining tiles on the board? [Solve without the most obvious method] + +
+ Solution + No. Given the design of a chess board, each domino would have to cover both a light and dark tile, but the tiles at opposing corners share the same color. +
+ +## Reservior Golfers + +Four golfers named Mr. Black, Mr. White, Mr. Brown and Mr. Blue were competing in a tournament. The caddy didn't know their names, so he asked them. One of them, Mr. Brown, told a lie. +The 1st golfer said "The 2nd Golfer is Mr. Black." +The 2nd golfer said "I am not Mr. Blue!" +The 3rd golfer said "Mr. White? That's the 4th golfer." +And the 4th golfer remained silent. +Which is which? + +
+ Solution + In order: White, Black, Brown, Blue +
+ +Riddle: The Rainfall Problem + +??? + +
+ Solution + ??? +
+ +## Very Contrived Situation + +You buy a mansion. Right when you go inside, a robber jumps in through a window. He sees you and asks you to tell him which of the 3 switches in front of him turns on the attic light. If you lie to him, he will kill you. He lets you walk up the stairs once, but only once. Because you just bought the house, how will you know which switch turns on the attic light bulb? + +
+ Solution + You turn the 1st switch on and wait for 10 minutes. Then, you turn the 1st switch off and the 2nd switch on. You immediately run up to the attic. If the light is on, the 2nd switch is the one that turns the light on. If the light is off, you feel the bulb. If the bulb is hot, it's the 1st switch. If the bulb is not hot, it's the 3rd switch. +
+ +## Island Fire + +On island trapped by mountains, totally forest, starts on fire in west, wind blows it east until it burn everything on island, how survive? + +
+ Solution + Take a lil burn, bring to unburn, burn, stand. +
+ +Riddle: There are three opaque boxes. One with mints in it, another with aniseed sweets and in the third a mixture of the two. They are all labeled incorrectly. What is the minimum number of sweets you can take to work out which box is which? + +
+ Solution + Just 1, from the box labeled mix. +
+ +## The Emperor's New Game + +You are a prisoner sentenced to death. The Emperor offers you a chance to live by playing a simple game. He gives you 50 black marbles, 50 white marbles and 2 empty bowls. He then says, 'Divide these 100 marbles into these 2 bowls. You can divide them any way you like as long as you use all the marbles. Then I will blindfold you and mix the bowls around. You then can choose one bowl and remove ONE marble. If the marble is WHITE you will live, but if the marble is BLACK... you will die.' How do you divide the marbles up so that you have the greatest probability of choosing a WHITE marble? + +
+ Solution + Place 1 white marble in one bowl, and place the rest of the marbles in the other bowl (49 whites, and 50 blacks). This way you begin with a 50/50 chance of choosing the bowl with just one white marble, therefore life! BUT even if you choose the other bowl, you still have ALMOST a 50/50 chance at picking one of the 49 white marbles. +
+ +## The Overtold Funeral Riddle + +A young woman is attending her mother's funeral. While there, she meets a man she has never seen before and falls in love immediately. After the funeral she tries to find him but cannot. Several days later she kills her sister. Why does she kill her sister? + +
+ Solution + She killed her sister in hopes that the man would be at the funeral. +
diff --git a/src/content/puzzle/example-riddles.md b/src/content/puzzle/example-riddles.md new file mode 100644 index 0000000..90b6ac8 --- /dev/null +++ b/src/content/puzzle/example-riddles.md @@ -0,0 +1,75 @@ +--- +title: Example Riddles +meta_title: Example Riddles +description: It's Example Riddles. +date: 2023-09-01T05:00:00Z +author: Reed Nelson +draft: true +--- + +
+Table of Contents + +- [Green Glass Door](#green-glass-door) +- [Good Line/Bad Line](#good-linebad-line) +- [Magic Moon \[visual riddle\]](#magic-moon-visual-riddle) +- [Egyptian Counting \[visual riddle\]](#egyptian-counting-visual-riddle) +- [Black Magic](#black-magic) +- [Magic Square](#magic-square) + +
+ +## Green Glass Door + +Ex. "There are trees behind the green glass door, but no leaves" + +
+ Solution + The only things behind the green glass door have pairs of letters in the word. +
+ +## Good Line/Bad Line + +Riddle: Ex. "Okay, from ____ to ____ is a good line." and "From ____ to ____ is a bad line." + +
+ Solution + The line between two objects is only a good line if the word "okay" is said before the declaration of whether it's a good or bad line. +
+ +## Magic Moon [visual riddle] + +The 'riddler' begins with a stick in the right hand declaring in some way that they're about to describe their magic moon, and uses the stick it as a brush to draw out whatever they describe in the air, then brings the stick to their left hand, drawing another object, and finishes with the phrase "That's my magic moon." + +
+ Solution + yeah +
+ +## Egyptian Counting [visual riddle] + +
+ Solution + Make a little figure on the table with whatever’s available (phone, keys, etc.) and ask what number that figure represents. However many fingers you have on the table is the answer. +
+ +## Black Magic + +Yeah + +
+ Solution + yeah +
+ +## Magic Square + +3 x 3 square, all triples (across, down, and diagonal) must sum to 15. Use 1-9 once each. + +
+ Solution + One solution: + |4|9|2| + |3|5|7| + |8|1|6| +
diff --git a/src/content/puzzle/low-grade-riddles.md b/src/content/puzzle/low-grade-riddles.md new file mode 100644 index 0000000..f709e77 --- /dev/null +++ b/src/content/puzzle/low-grade-riddles.md @@ -0,0 +1,64 @@ +--- +title: Low Grade Riddles +meta_title: Low Grade Riddles +description: It's Low Grade Riddles. +date: 2023-09-01T05:00:00Z +author: Reed Nelson +draft: true +--- + +
+Table of Contents + +- [Desert Canoe](#desert-canoe) +- [Barn Roof](#barn-roof) +- [Stop and Go](#stop-and-go) +- [Mary's Shower](#marys-shower) +- [Hunger in the Arctic](#hunger-in-the-arctic) + +
+ +## Desert Canoe + +Two people are canoeing through the desert. One says "wears the paddle", and the other replies, "sure does." How does this make sense? + +
+ Solution + If you read this, the riddle should be how this is a riddle. +
+ +## Barn Roof + +A rooster lays an egg on the roof of a barn. Which side does it roll off? + +
+ Solution + Rethink your life. +
+ +## Stop and Go + +When does green mean stop and red mean go? + +
+ Solution + A watermelon. +
+ +## Mary's Shower + +Mary gets in the shower, but surprisingly her hair is not wet when she gets out. How is this possible? + +
+ Solution + She didn't turn the water on. +
+ +## Hunger in the Arctic + +No matter how terrible things get for the people of the Arctic, they will not eat a penguin. + +
+ Solution + Penguins live in Antarctica. +
diff --git a/src/content/blog/ent.md b/src/content/puzzle/number-theory.md similarity index 99% rename from src/content/blog/ent.md rename to src/content/puzzle/number-theory.md index 6cd9e07..63df23d 100644 --- a/src/content/blog/ent.md +++ b/src/content/puzzle/number-theory.md @@ -3,10 +3,7 @@ title: Fun Problems in Number Theory meta_title: Fun Problems in Number Theory description: Number Theory contains a rich set of interesting problems, some suitable for you or I, some entirely unsolvable. This unconventional post is a selection of my favorite problems, along with my solutions to them. date: 2023-09-01T05:00:00Z -categories: [Mathematics] author: Reed Nelson -tags: [math, puzzles] -complexity: 0 draft: true --- diff --git a/src/content/riddles/-index.mdx b/src/content/puzzle/riddles.md similarity index 99% rename from src/content/riddles/-index.mdx rename to src/content/puzzle/riddles.md index 2ea865b..21b0be8 100644 --- a/src/content/riddles/-index.mdx +++ b/src/content/puzzle/riddles.md @@ -1,6 +1,10 @@ --- title: Riddles meta_title: Riddles +description: It's Riddles. +date: 2023-09-01T05:00:00Z +author: Reed Nelson +draft: true ---
diff --git a/src/content/puzzle/situation-riddles.md b/src/content/puzzle/situation-riddles.md new file mode 100644 index 0000000..b6fabde --- /dev/null +++ b/src/content/puzzle/situation-riddles.md @@ -0,0 +1,91 @@ +--- +title: Riddles +meta_title: Riddles +description: It's Riddles. +date: 2023-09-01T05:00:00Z +author: Reed Nelson +draft: true +--- + +
+Table of Contents + +- [Albatross](#albatross) +- [The Dust](#the-dust) +- [Rainy Elevator](#rainy-elevator) +- [Scores](#scores) +- [Cactus](#cactus) +- [Abel and Cain](#abel-and-cain) +- [A rope breaks. A bell rings. A man dies.](#a-rope-breaks-a-bell-rings-a-man-dies) + +
+ +## Albatross + +A man goes to a seaside restaurant and orders Albatross. When his food arrives, he takes a bite, pulls out a gun, and shoots himself in the head. + +
+ Solution + Years ago or whatever the man was in a plane crash, where only he and his friend and some stranger survived impact and made it to a desert island. After several weeks will little food, the stranger and the friend go hunting deeper in the island while The Man, TM, just dicks around on the beach or something. Mr. Stranger kills and cuts up Friendo on this hunting outing, then comes back with the story that Friend died somehow but they managed to find some albatross, and here have some. In the next couple days they’re rescued, and part ways for good. Some time later Man decides he wants some more albatross for old times sake or something, but when he tastes it, he realizes what he had on the island was not albatross. Wham bam thank you ma’am. +
+ +## The Dust + +If he had seen the dust, he would have lived. + +
+ Solution + *He* is a short person, the shortest person around actually, and he’s in a freak show for that reason. He’s also blind. There’s this other short person who’s not so good at being short, so out of jealousy he slowly grinds down the blind one’s cane, so as to make the blind man feel as though he’s growing. This succeeds, and the blind man is so bummed about losing the one thing that makes him cool that he ends it all. But of course if he had seen the sawdust he would have recognized the deception and lived. +
+ +## Rainy Elevator + +A guy can take the elevator all the way up when it's raining, but only half way up when it's sunny. + +
+ Solution + The guy is a short person. He can reach all the buttons only when he has his umbrella with him. +
+ +## Scores + +A man wakes up in the morning, looks outside, and sees scores of people in his yard. + +
+ Solution + The man is a lighthouse keeper. Who lives in a lighthouse. His yard is a rocky shore. He forgot to light the lighthouse one night, a ship got wrecked, bodies washed up. You get worked. +
+ +## Cactus + +A man lies dead next to a cactus. Stuck to the cactus is a slip of paper. + +
+ Solution + The man was lost in the desert for days. He couldn't find any landmarks, so he started sticking slips of paper to cactuses he passed. After another day of walking, with almost no water left, he came across this cactus, which had a slip of paper on it already; he knew that he was walking in circles, so rather than wait to die of thirst he shot himself. +
+ +## Abel and Cain + +Abel walks out of the ocean. Cain asks him who he is, and Abel answers. Cain kills Abel. + +
+ Solution + Abel is a prince of the island nation that he landed on. A cruel and warlike prince, he waged many land and naval battles along with his father the king. In one naval encounter, their ship sank, the king died, and the prince swam to a deserted island where he spent several months building a raft or small boat. In the meantime, a regent was appointed to the island nation, and he brought peace and prosperity. When Prince Abel returned to his kingdom, Cain (a native fisherman) realized that the peace of the land would only be maintained if Abel did not reascend to his throne, and killed the prince (with a piece of driftwood or some other impromptu weapon). +
+ +## A rope breaks. A bell rings. A man dies. + +A rope breaks. A bell rings. A man dies. + +
+ Solution + A blind man enjoys walking near a cliff, and uses the sound of a buoy to gauge his distance from the edge. One day the buoy's anchor rope breaks, allowing the buoy to drift away from the shore, and the man walks over the edge of the cliff. +
+ +Riddle: A woman buys a new pair of shoes, goes to work, and dies. + +
+ Solution + The woman is the assistant to a circus knife-thrower. The new shoes have higher heels than she normally wears, so that the thrower misjudges his aim and one of his knives kills her during the show. +
diff --git a/src/layouts/PuzzleSingle.astro b/src/layouts/PuzzleSingle.astro new file mode 100644 index 0000000..27875ef --- /dev/null +++ b/src/layouts/PuzzleSingle.astro @@ -0,0 +1,52 @@ +--- +import Share from "@/components/Share.astro"; +import config from "@/config/config.json"; +import dateFormat from "@/lib/utils/dateFormat"; +import { humanize, markdownify, slugify } from "@/lib/utils/textConverter"; + +import { + FaRegCalendarAlt, + FaRegUserCircle, +} from "react-icons/fa/index.js"; + +const { puzzle_folder } = config.settings; +const { post } = Astro.props; +const { Content } = await post.render(); +const { title, description, author, categories, date, tags } = post.data; + +categories.sort((a: string, b: string) => a.localeCompare(b)); +tags.sort((a: string, b: string) => a.localeCompare(b)); +--- + +
+
+
+
+

+
    +
  • + + {humanize(author)} +
  • +
  • + + {dateFormat(date)} +
  • +
+
+ +
+
+
+ +
+
+

+
+
diff --git a/src/layouts/components/PuzzleCard.astro b/src/layouts/components/PuzzleCard.astro new file mode 100644 index 0000000..6ac3378 --- /dev/null +++ b/src/layouts/components/PuzzleCard.astro @@ -0,0 +1,26 @@ +--- +import config from "@/config/config.json"; + +const { + summary_length, + puzzle_folder, +}: { summary_length: number; puzzle_folder: string } = config.settings; +const { data } = Astro.props; +const { title, description } = data.data; +--- + +
+

+ + {title} + +

+ +

{description}

+ + read more + +
diff --git a/src/pages/puzzle/[single].astro b/src/pages/puzzle/[single].astro new file mode 100644 index 0000000..602809a --- /dev/null +++ b/src/pages/puzzle/[single].astro @@ -0,0 +1,29 @@ +--- +import config from "@/config/config.json"; +import Base from "@/layouts/Base.astro"; +import PuzzleSingle from "@/layouts/PuzzleSingle.astro"; +import { getSinglePage } from "@/lib/contentParser.astro"; + +export async function getStaticPaths() { + const posts = await getSinglePage(config.settings.puzzle_folder); + + const paths = posts.map((post) => ({ + params: { + single: post.slug, + }, + props: { post }, + })); + return paths; +} + +const { post } = Astro.props; +const { title, meta_title, description } = post.data; +--- + + + + diff --git a/src/pages/puzzle/index.astro b/src/pages/puzzle/index.astro new file mode 100644 index 0000000..bea2e3d --- /dev/null +++ b/src/pages/puzzle/index.astro @@ -0,0 +1,57 @@ +--- +import PuzzleCard from "@/components/PuzzleCard.astro"; +import Pagination from "@/components/Pagination.astro"; +import config from "@/config/config.json"; +import Base from "@/layouts/Base.astro"; +import { getSinglePage } from "@/lib/contentParser.astro"; +import { sortByDate } from "@/lib/utils/sortFunctions"; +import PageHeader from "@/partials/PageHeader.astro"; +import BlogSidebar from "@/partials/BlogSidebar.astro"; +import { getEntryBySlug } from "astro:content"; + +const { puzzle_folder } = config.settings; +const postIndex = await getEntryBySlug(puzzle_folder, "-index"); +const posts = await getSinglePage(puzzle_folder); +const sortedPosts = sortByDate(posts); +const totalPages: number = Math.ceil(posts.length / config.settings.puzzle_pagination); +const currentPosts = sortedPosts.slice(0, config.settings.puzzle_pagination); +--- + + + +
+
+
+ +
+
+ { + currentPosts.map((post) => ( +
+ +
+ )) + } +
+ +
+ + + +
+
+
+ diff --git a/src/pages/puzzle/page/[slug].astro b/src/pages/puzzle/page/[slug].astro new file mode 100644 index 0000000..622d3b5 --- /dev/null +++ b/src/pages/puzzle/page/[slug].astro @@ -0,0 +1,76 @@ +--- +import PuzzleCard from "@/components/PuzzleCard.astro"; +import Pagination from "@/components/Pagination.astro"; +import config from "@/config/config.json"; +import Base from "@/layouts/Base.astro"; +import { getSinglePage } from "@/lib/contentParser.astro"; +import { sortByDate } from "@/lib/utils/sortFunctions"; +import PageHeader from "@/partials/PageHeader.astro"; +import BlogSidebar from "@/partials/BlogSidebar.astro"; +import { getEntryBySlug } from "astro:content"; + +const { puzzle_folder } = config.settings; +const { slug } = Astro.params; +const postIndex = await getEntryBySlug(puzzle_folder, "-index"); +const posts = await getSinglePage(puzzle_folder); +const sortedPosts = sortByDate(posts); +const totalPages = Math.ceil(posts.length / config.settings.puzzle_pagination); +const currentPage = slug && !isNaN(Number(slug)) ? Number(slug) : 1; +const indexOfLastPost = currentPage * config.settings.puzzle_pagination; +const indexOfFirstPost = indexOfLastPost - config.settings.puzzle_pagination; +const currentPosts = sortedPosts.slice(indexOfFirstPost, indexOfLastPost); + +export async function getStaticPaths() { + const posts = await getSinglePage(config.settings.puzzle_folder); + const totalPages = Math.ceil(posts.length / config.settings.puzzle_pagination); + const paths = []; + + for (let i = 1; i < totalPages; i++) { + paths.push({ + params: { + slug: (i + 1).toString(), + }, + }); + } + return paths; +} +--- + + + +
+
+
+ +
+
+ { + currentPosts.map((post) => ( +
+ +
+ )) + } +
+ +
+ + +
+
+
+ diff --git a/src/pages/riddles.astro b/src/pages/riddles.astro deleted file mode 100644 index 3a71b7b..0000000 --- a/src/pages/riddles.astro +++ /dev/null @@ -1,27 +0,0 @@ ---- -import Base from "@/layouts/Base.astro"; -import PageHeader from "@/partials/PageHeader.astro"; -import { getEntryBySlug } from "astro:content"; - -const riddles = await getEntryBySlug("riddles", "-index"); -const { Content } = await riddles.render(); -const { title, meta_title } = riddles.data; ---- - - - -
-
-
-
-
- -
-
-
-
-
-