README.md

AO3 Loader #

A small Astro site that turns a folder of fanfiction files into pages you can read on your website. The works can come from an author's AO3 profile, from EPUBs and PDFs you downloaded from AO3, or from Markdown files you wrote yourself.

It's an example of an Astro content loader. Yours to copy and play around with!

Getting started #

You'll need Node.js 22.12 or newer. Install the dependencies, then start the site:

npm install
npm run dev
Command Action
npm install Installs dependencies
npm run dev Starts the local dev server at localhost:4321
npm run typecheck Checks TypeScript and Astro files
npm run build Builds your production site to ./dist/
npm run preview Previews your build locally, before deploying

What the site looks like #

Works list page #

See: ao3-loader/src/pages/index.astro

Screenshot of the home page: a list of fics, each with its title, author,
kudos count, a "Read chapter 1" link, a "Read on AO3" link, its fandoms, and
its summary

Work page #

See: ao3-loader/src/pages/works/[workId]/chapters/[chapterNumber].astro

With placeholder content since we can't get chapters from AO3 right now 🥲

Screenshot of a chapter page for "Wishing Well" by astolat: a "Back home"
link, an expandable list of all three chapters with the current one in bold,
the work's note, the chapter title, summary, and note, the chapter text, and a
"Next chapter" link

Adding works #

Put them in the One Folder™: src/content/fanfics/. They can go inside subfolders too, so organize them however you like. The loader can tell what each file is from its name, and skips loading any file that isn't named like these:

A file named like this... ...is read as
Wishing Well.epub, Wishing Well.pdf A work you downloaded from AO3
Danger High Voltage.work.md A one-shot you wrote in Markdown
A folder with a _work.yaml and .chapter.md files A multichapter work you wrote in Markdown
Wishing Well.ao3.yaml A work the loader saved from AO3 for you (how)

Every time you run npm run dev or npm run build, the loader reads every work it finds in the folder and hands them to Astro, which checks that each one is actually shaped like the fanfics it expects. If a file has a mistake, the build stops, and the error should tell you the problem and what file to fix.

The terminal shows every work that was loaded, so you can check that yours made it in.

Note

If the same work is in the folder more than once, like an EPUB and a PDF of the same fic, the loader keeps only one copy, picking the first it finds in this order: a Markdown work you wrote, a work the loader saved, an EPUB, then a PDF. The terminal names each file that was left out, and the file that was kept instead.

Downloading from an AO3 profile #

The loader doesn't just show what's already in its folder. It can also fill the folder for you, by downloading an author's works from AO3 and saving them in src/content/fanfics/.

Setting up the manifest #

To set up the loader to download from AO3, you list the author in a file called manifest.yaml:

  1. Copy src/content/fanfics/manifest.example.yaml to a new file named manifest.yaml, in the same folder
  2. Replace astolat after author: with the author's AO3 username, and change folder_name to where you want their works saved. Remove the settings you don't need
  3. Run npm run dev

From then on, every run downloads the author's works before loading the folder. Each work is saved as a .ao3.yaml file, in a folder named after the author (or the folder_name you pick), and is loaded like any other file in there.

Manifest options #

The manifest only decides what gets downloaded. The Astro site still shows everything in the folder, whether the manifest mentions it or not:

  • download: false => stops asking AO3 for this author's works, and keeps showing the ones already saved
  • chapters: true => also downloads the text of every chapter, which makes each run slower
  • exclude => skips works in the fandoms you list, or posted under the pseuds you list

Every option is explained in manifest.example.yaml.

Important

While download is on, every run saves the author's works again, and replaces each saved file with what AO3 sends:

  • An edit you made to a saved file is lost, and a saved file you deleted comes back
  • Chapters saved by an earlier run are lost if chapters is false, or if AO3 doesn't send a work's chapters this time

Note

The loader never deletes a saved file. If you change folder_name, organize_by, or name_by, or the author renames a work on AO3, the old file stays where it was, and the site can show either copy. Delete the old files yourself.

EPUBs and PDFs from AO3 #

Drop the EPUBs and PDFs you downloaded from AO3 anywhere in src/content/fanfics/. They show up on the site like any other work.

Writing your own works #

You can also write works yourself, in Markdown.

One-shots #

A one-shot is a single file whose name ends in .work.md. The work's details go at the top, between the --- lines, and the text goes below them:

---
# Titles with ": " in them need quotes
title: "Danger: High Voltage"
author: boba-tan
fandoms: [Binary Calls]
tags:
  characters: [NAND Cypher, Reader]
  relationships: [NAND Cypher/Reader]
  additional: [Mutual Pining]
# Use | for a multiline summary (with markdown support). Always indent by the
# same amount of blank spaces
summary: |
  Reader finds out resistance _is_, after all, futile.

  Written for the ["Ohm Sweet Ohm" challenge](https://fujocoded.com).
---

A triangular outline loomed through the frosted pane, slender
cables crackling in the electric night.

The doorbell rang. The lights flickered.

_Reader's heart followed suit._

Only title and author are needed. For more than one author, write authors: [boba-tan, CSS] instead. A work with no author stops the build.

Everything else is optional:

  • The tag types are yours to name, so you're not stuck with AO3's
  • Most fields an AO3 work has (rating, language, adult, complete, and so on) can go here too. The full list is otherWorkSchema, in src/content/fanfics/_config/your-works.ts
  • url, shortUrl, host, and stats can't, since your work isn't on AO3. Writing one stops the build
  • The loader counts your chapters for you. Write chapters yourself to change it, like chapters: { published: 3, total: 5 }
  • The loader doesn't count words. To show a word count, write it yourself, like words: 1234

Lists can also be written one item per line, which is easier to read when they get long:

fandoms:
  - Binary Calls
tags:
  characters:
    - NAND Cypher
    - Reader
  relationships:
    - NAND Cypher/Reader
  additional:
    - Enemies to lovers
    - Only One Server Rack
    - NAND Cypher Is Bad at Feelings

Multichapter works #

A multichapter work is a folder. The work's details go in a file named _work.yaml, and each chapter is its own file, with a name that ends in .chapter.md:

Binary Calls/Opposites Conduct/_work.yaml
Binary Calls/Opposites Conduct/01-clinging-with-static.chapter.md
Binary Calls/Opposites Conduct/02-spark-then-surge.chapter.md

_work.yaml holds the same details as the top of a one-shot, without the --- lines. The underscore means "this file is about the folder it's in, it's not a chapter". It also keeps the file at the top of the folder.

title: Opposites Conduct
author: boba-tan
fandoms: [Binary Calls]

A folder with a _work.yaml and no .chapter.md file stops the build, with a message that names the folder.

A chapter file can have its own title, summary, and notes at the top, or nothing at all:

---
title: Clinging with Static
summary: When voltage runs high, NAND Cypher is suddenly jealous.
notes:
  start: Don't like, don't read
  end: |
    Thanks to my beta!

    Next chapter on Friday.
---

"You sound like a power freak." The words are out of my mouth
before I can stop them. "I think we could use a breaker."

Chapter order #

Every .chapter.md file in the folder is loaded, in alphabetical order. Starting each name with a number (01-, 02-) is the easy way to get the order you want. 2 comes before 10, so you don't have to write 02...we just like keeping our file prefixes the same length.

To number the chapters yourself without relying on order, give each one an index. It always wins over the name of the file:

---
index: 2
title: Spark, Then Surge
---

Important

You can skip numbers (1, 2, 5). Two things stop the build, with a message that names the files to fix:

  • An index on some chapters of a work but not on others. It's every chapter or none
  • The same index on two chapters of a work

Things to know #

  • The summary and notes are Markdown too, like the text
  • The id can be left out. The loader makes one from the first author's username and the title (boba-tan-danger-high-voltage above). If two of your works end up with the same id, only one is kept, and the terminal says which
  • To replace a work the loader saved, or an EPUB or PDF, with your own version, give your Markdown work the same id: the number in the work's AO3 link
  • Other .md files, like a README or your notes, are left alone

Changing the loader #

The loader's code is in src/content/fanfics/_config/. Start with index.ts: it reads top to bottom, from what a work looks like to how Astro gets them.

The _config README says what's in each file, and where to make the most common changes.