Popup-from-html
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
index.ts
https://cyberskunk--4d6f2d10354811f0bae59e149126039e.web.val.run
This Val Town project provides an HTTP endpoint that fetches and displays specific sections from a technical rules document based on their HTML IDs.
- Fetches sections from the technical rules document at https://cyberskunk.xyz/q-n-a/rules/Technical_rules.html
- Allows referencing specific rules by their ID (e.g., t66)
- Lists all available rule IDs for easy discovery
- Caches the document to reduce load on the source server
- Provides a simple web interface for accessing rules
- Offers JSON API endpoints for programmatic access
- Get All Articles - View a grid of all available rule IDs
- Open Original Document - View the source technical rules document
To access a specific rule in HTML format, use the following URL format:
/rule/{ruleId}
For example, to access rule t66:
/rule/t66
To see a list of all available rules in HTML format:
/rules
This will display a grid of all rule IDs that you can click to view.
For programmatic access, the following JSON endpoints are available:
/api/rule/{ruleId}
Example response:
{ "id": "t66", "originalQuery": "t66", "content": "<div id=\"t66\">...</div>..." }
/api/rules
Example response:
{ "rules": ["t1", "t2", "t3", ...] }
The home page (/
) provides usage instructions and links to example rules.
- Uses cheerio for HTML parsing on the server side
- Implements caching to avoid fetching the document on every request
- Extracts and sorts rule IDs for easy navigation
- Provides formatted HTML output for better readability
- Offers JSON API endpoints with CORS support for cross-origin requests
Potential enhancements for this project:
- Add a search functionality to find rules by keywords
- Implement a more detailed table of contents showing rule titles
- Add support for fetching multiple rules at once
- Improve styling and mobile responsiveness
- Add a feature to extract and display rule titles alongside IDs