Building a Mystery Site Without Build and Using One HTML File: The Mechanism of "Reika Jikenbo" Running on GitHub Pages
- JavaScript
- GithubPages
- HTML
- AI
- Personal Development
I have published the mystery site "Reika Jikenbo" (Zero Class Case Book). It is a site where you can solve a small mystery every day and uncover the truth through several chapters in the "event file".
This site operates with just one HTML file. There is no server, no database, and no build process. It is simply placed on GitHub and published via GitHub Pages. The source code can be viewed at shoyo-maya-bot/reika-jikenbo.
In this article, I will introduce how to create a site that can have "daily changing puzzles", "progress tracking", and "adding series" using only HTML, CSS, and JavaScript within the index.html file. There are no spoilers for the mystery answers, so even those who haven't played yet can read it safely.
What Kind of Site?
| Features | Content |
|---|---|
| Today's Small Mystery | The problem changes every day at midnight (Japan Time). It shows the number of consecutive correct days and the records of the last 7 days. |
| Event File | One event consists of four chapters and a final chapter. You progress by reading materials and answering questions. Hints can be provided in stages. |
| Detective Notebook | Points accumulate based on the number of puzzles solved, allowing the rank to increase starting from "Patrolman". |
| Next Preview | Countdown to the release of the next event file. |
| Sharing Results | After solving, you can copy the time taken and the number of hints used (without including the answer). |
This site is built using only HTML, CSS, and JavaScript within the index.html file.
Structure: Only Three Files
The repository contains only these three files.
GitHub Pages will publish your files after processing them with Jekyll by default. By placing a .nojekyll file, it will skip the Jekyll processing and publish the files as they are. This is sufficient for a single-file site.
To publish, simply select the branch you want to publish in the Pages section of the repository's Settings. After pushing, wait a bit and the site will be updated.
Mechanism 1: Separating the code and data
What I value most in this site is keeping the code that creates the screen separate from the content of the puzzles (data).
Event files, daily puzzles, and next episode previews are written as JavaScript arrays and objects respectively.
One chapter is structured like this (the content is dummy for explanation).
Document Title
...`, q:"Question Article", answers:["こたえ", "答え"], hints:["1つ目のヒント", "2つ目のヒント"], reveal:{ head:"答え:…", body:"解説の文章" } }The function to create the screen reads this data and displays it in the same format for any event. When adding a new event, you just need to write one data entry and add it to FILES. The README also states this as follows.
Event files are FILES array, today's riddle is DAILY array, and edit NEXT to add the next preview.
Makes it easier to request additions from AI
When the data format is fixed, it's also convenient to ask AI to add new problems. Since the format is fixed, you don't have to worry about AI changing the code on its own.
For example, if you ask an agent-type AI, you would write:
Please add 5 riddles to the DAILY array in index.html. Align them with the existing problem's format (q, a, ex), and include answers with variations in notation in the a field. Do not change the code for creating the screen.
The key is to write about 'where', 'in what format', and 'what not to change'. This is the same approach as the article mentioned earlier, where instructions for an agent should specify the scope, completion conditions, and what not to do.
Mechanism 2: Changing the problem every day without a server
If you think about a site that changes the problem every day, it seems like a mechanism is needed for the server to check the date and select a problem. However, in this site, the calculation is done on the visitor's browser.
- Add 9 hours to the current time (in milliseconds) to convert it to Japan Time
- Divide by the number of milliseconds in a day (86400e3) to get a continuous day number since January 1, 1970
- Use this number modulo the number of problems in DAILY to select today's problem
The continuous day number increments by 1 at midnight Japan Time, so the problem changes at that time. Regardless of the country, the same problem will be shown at the same time.
When all problems are used up, it loops back to the first one. However, adding more problems to DAILY extends the time until it cycles back.
The number of consecutive correct days is also counted using this continuous day number. It records the day number of correct answers and counts backward from today (if not solved yet, from yesterday) to determine the streak.
Mechanism 3: Absorb answer format variations
In puzzle-solving, judging the answer is crucial. If an answer is correct but formatted differently, it can disappoint players.
This site compares the input answer and the correct answer after normalizing both using the same rules.
We are consolidating different ways of writing time, such as '3:15 PM', '15:15', and '3:15', into a single regex check.
Mechanism 4: Save progress in the browser
Chapters solved, number of hints used, and records of daily small riddles are saved in the browser's localStorage.
Weaknesses of this approach
Of course, there are also limitations to a static site in one file.
Answers are visible in the source
Since the answer judgment is done in the browser, the answers can be read by opening the page source. This is acceptable for casual sites, but if you are creating a ranking or offering prizes, you need to take measures such as using a hash value for the answers or moving the judgment to the server.
Records are not shared between devices
localStorage saves data per browser, so records on a smartphone and a PC will be separate.
Files become too large
As you add more event files, the index.html file becomes longer. If the number of events increases, it's a good idea to split the data into separate JSON files for each event.
The key point is to do the third step first. Once the data format is decided, adding new questions becomes easy, whether you do it yourself or rely on AI.
Common mistakes when creating yourself
Writing questions directly into the display code
Writing HTML for each question leads to having to modify the display code every time a new question is added, making it more prone to errors. Separate the questions into data.
Making the answer judgment too strict
If you consider answers incorrect based on differences like full-width vs. half-width characters or katakana vs. hiragana, players will gradually leave.
Before comparing, let's prepare both with the same rules.
Assume that localStorage is always available
In environments where it's not available, the script may stop with an exception, and the site may become blank. Wrap reading and writing in try.
Change the format of the answer but keep the key the same
Old data may be read by new code, causing display issues. If the format changes, increase the key version and move old data if necessary.
Summary
You can create a "daily playable" site with some creativity even without a server or build process.
- Separate the problem from the data, and just write the data when adding new content.
- Perform date calculations in the browser and change content daily without a server.
- Adjust the formatting of the answers before comparing to ensure consistency.
- Save progress in the browser and avoid storing personal information.
Zero Lesson Notebook will continue to add event files. The next "FILE 03" is scheduled to be published at 7:00 PM on October 18th. Feel free to try it, detective.
This article is also posted on Zenn.
Go to list of users who liked
Go to list of comments
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme