A command-line interface for fetching and displaying top stories from Hacker News.
hns
is a simple, fast Rust command-line tool that pulls top stories from the official Hacker News API and displays them in a clean, readable format. The tool shows story titles, authors, timestamps, text content, and URLs in a structured way, making it easy to browse Hacker News without leaving your terminal.
- Fetch and display the top stories from Hacker News
- Configurable number of stories to display
- Clean formatting with proper handling of HTML content
- Special handling for "Show HN" posts
- Proper decoding of HTML entities
- AI-powered URL summarization using Ollama's gemma3:4b model
% hns --summarize
Ensure you have Rust and Cargo installed. Then:
# Clone the repository
git clone https://github.com/yourusername/hns.git
cd hns
# Build and install
cargo install --path .
To use the --summarize
feature, you need to have Ollama running with the gemma3:4b model installed:
- Install Ollama following the official instructions
- Pull the gemma3:4b model:
ollama pull gemma3:4b
- Ensure Ollama is running before using the
--summarize
flag
# Start Ollama (keep running in a separate terminal)
ollama serve
Run the tool with default settings (shows 5 top stories):
hns
Argument | Short | Description | Default | Range |
---|---|---|---|---|
--max-stories |
-m |
Maximum number of stories to display | 5 | 1-25 |
--summarize |
Enable URL summarization using gemma3:4b model | false | - | |
--help |
-h |
Display help information | - | - |
--version |
-V |
Display version information | - | - |
Display the top 10 stories:
hns -m 10
Display the maximum number of stories:
hns --max-stories 25
Display stories with URL summaries:
hns --summarize
Display 10 stories with URL summaries:
hns -m 10 --summarize
For each story, the tool displays:
- A separator line
- Timestamp, author, and story ID
- Story title
- For "Show HN" posts: URL followed by text content (if available)
- For regular posts: Text content (if available) or URL
- Rust 1.70.0 or higher
- Cargo
The project includes several files to help with development:
Makefile
- Common development tasks (runmake help
for details)CHANGELOG.md
- Track changes between versionsCONTRIBUTING.md
- Guidelines for contributors
clap
- Command-line argument parsingreqwest
- HTTP client for API requests (and Ollama API calls)tokio
- Asynchronous runtimeserde
- JSON serialization/deserializationserde_json
- JSON serialization/deserialization for Ollama APIchrono
- Timestamp formattingscraper
- HTML parsingego-tree
- Tree data structure for HTML parsinghtml2text
- HTML to text conversion for URL content
# Clone the repository
git clone https://github.com/yourusername/hns.git
cd hns
# Build in debug mode
cargo build
# Build in release mode
cargo build --release
cargo test
This project uses GitHub Actions for continuous integration and deployment. The workflow automatically:
- Tests the codebase
- Builds binaries for multiple platforms (Linux, macOS Intel/ARM, Windows)
- Creates GitHub releases with packaged artifacts when tags are pushed
- Publishes to crates.io when a new version is tagged
To create a new release:
# 1. Update the version in Cargo.toml
# 2. Commit the changes
git add Cargo.toml
git commit -m "Bump version to x.y.z"
# 3. Tag the commit
git tag -a vx.y.z -m "Release version x.y.z"
# 4. Push to GitHub with tags
git push && git push --tags
Note: To enable publishing to crates.io, you must set the
CRATES_IO_TOKEN
secret in your GitHub repository settings.
This tool uses the official Hacker News API:
This project is licensed under the BSD 3-Clause License - see the LICENSE.md file for details.