3 Commits

Author SHA1 Message Date
Claude
52c326eed1 Merge branch 'claude/fix-bugs-and-gaps-01DvJSzruQh49DU6XK5AykQU'
# Conflicts:
#	internal/config/config.go
#	internal/config/config_test.go
2025-11-27 16:41:10 +00:00
Claude
ff13012408 fix: address functionality gaps identified in code review
- Wire up --config/-f flag to actually load custom config files
  - Move config loading to PersistentPreRunE in root.go
  - Simplify main.go to just call cmd.Execute()
  - Move Playwright init to web command's PreRunE/PostRunE

- Remove unused functions from cmd/web.go (~90 lines of dead code)
  - Remove writeSingleFile, writeMultipleFiles, generateDefaultFilename
  - Remove scrapeURL, extractAndConvertContent, testExtractAndConvertContent
  - Remove unused mock function from web_test.go

- Add OutputType validation to Config.Validate()
  - Only allow "single", "separate", or empty string
  - Add test cases for valid and invalid output types
2025-11-27 16:05:42 +00:00
Claude
09608cf073 fix: resolve 5 bugs identified in code review
- Fix malformed YAML in config_test.go (incorrect indentation)
- Add validation for empty file_extensions in Config.Validate()
- Remove obsolete max_depth test case (field no longer exists)
- Remove unused global cfg variable in main.go
- Fix race condition in ScrapeSites by counting URLs before goroutines
- Remove unreachable JavaScript code in scroll script, add proper delay
- Standardize file extensions to not include leading dot
2025-11-27 15:56:37 +00:00
2 changed files with 66 additions and 149 deletions

212
README.md
View File

@@ -1,225 +1,145 @@
# Rollup # Rollup
Rollup aggregates the contents of text-based files and webpages into markdown files. Rollup aggregates the contents of text-based files and webpages into a markdown file.
## Features ## Features
- **File aggregation**: Combine multiple source files into a single markdown document - File type filtering for targeted content aggregation
- **File type filtering**: Include only specific file extensions - Ignore patterns for excluding specific files or directories
- **Ignore patterns**: Exclude files/directories using glob patterns - Support for code-generated file detection and exclusion
- **Code-generated file detection**: Mark auto-generated files as read-only in output - Advanced web scraping functionality with depth control
- **Web scraping**: Scrape webpage content using Playwright browser automation - Verbose logging option for detailed operation insights
- **HTML to Markdown conversion**: Automatically converts scraped HTML to clean markdown - Exclusionary CSS selectors for precise web content extraction
- **CSS selectors**: Extract specific content sections or exclude unwanted elements - Support for multiple URLs in web scraping operations
- **Path-based overrides**: Configure different selectors for specific URL paths - Configurable output format for web scraping (single file or separate files)
- **Rate limiting**: Configurable requests per second and burst limits for web scraping - Flexible configuration file support (YAML)
- **Output modes**: Single combined file or separate files per source - Automatic generation of default configuration file
- **Verbose logging**: Detailed operation insights for debugging - Custom output file naming
- **YAML configuration**: Flexible configuration file support - Rate limiting for web scraping to respect server resources
## Installation ## Installation
Ensure you have Go 1.21+ installed, then run: To install Rollup, make sure you have Go installed on your system, then run:
```bash ```bash
go install github.com/tnypxl/rollup@latest go get github.com/tnypxl/rollup
```
Or build from source:
```bash
git clone https://github.com/tnypxl/rollup.git
cd rollup
go build -o rollup .
``` ```
## Usage ## Usage
Basic usage:
```bash ```bash
rollup [command] [flags] rollup [command] [flags]
``` ```
### Commands ### Commands
| Command | Description | - `rollup files`: Rollup files into a single Markdown file
|---------|-------------| - `rollup web`: Scrape main content from webpages and convert to Markdown
| `files` | Aggregate local files into a single markdown file | - `rollup generate`: Generate a rollup.yml config file
| `web` | Scrape webpages and convert to markdown |
| `generate` | Generate a default rollup.yml config file |
### Flags for `files` command ### Flags for `files` command
| Flag | Short | Default | Description | - `--path, -p`: Path to the project directory (default: current directory)
|------|-------|---------|-------------| - `--types, -t`: Comma-separated list of file extensions to include (default: .go,.md,.txt)
| `--path` | `-p` | `.` | Path to the project directory | - `--codegen, -g`: Comma-separated list of glob patterns for code-generated files
| `--types` | `-t` | `go,md,txt` | Comma-separated list of file extensions (without dots) | - `--ignore, -i`: Comma-separated list of glob patterns for files to ignore
| `--codegen` | `-g` | | Glob patterns for code-generated files |
| `--ignore` | `-i` | | Glob patterns for files to ignore |
### Flags for `web` command ### Flags for `web` command
| Flag | Short | Description | - `--urls, -u`: URLs of the webpages to scrape (comma-separated)
|------|-------|-------------| - `--output, -o`: Output type: 'single' for one file, 'separate' for multiple files (default: single)
| `--urls` | `-u` | URLs of webpages to scrape (comma-separated) | - `--depth, -d`: Depth of link traversal (default: 0, only scrape the given URLs)
| `--output` | `-o` | Output type: `single` or `separate` | - `--css`: CSS selector to extract specific content
| `--css` | | CSS selector to extract specific content | - `--exclude`: CSS selectors to exclude from the extracted content (comma-separated)
| `--exclude` | | CSS selectors to exclude (comma-separated) |
### Global flags ### Global flags
| Flag | Short | Description | - `--config, -f`: Path to the configuration file (default: rollup.yml in the current directory)
|------|-------|-------------| - `--verbose, -v`: Enable verbose logging
| `--config` | `-f` | Path to config file (default: `rollup.yml`) |
| `--verbose` | `-v` | Enable verbose logging |
## Configuration ## Configuration
Rollup reads from `rollup.yml` by default. Use `--config` to specify a different file. Rollup can be configured using a YAML file. By default, it looks for `rollup.yml` in the current directory. You can specify a different configuration file using the `--config` flag.
### Configuration Options Example `rollup.yml`:
```yaml ```yaml
# File extensions to include (without leading dots)
file_extensions: file_extensions:
- go - go
- md - md
- js
# Glob patterns for paths to ignore
ignore_paths: ignore_paths:
- node_modules/** - node_modules/**
- vendor/** - vendor/**
- .git/** - .git/**
# Glob patterns for code-generated files (marked as read-only in output)
code_generated_paths: code_generated_paths:
- "**/*.pb.go" - **/generated/**
- "**/generated/**"
# Web scraping site configurations
sites: sites:
- base_url: https://example.com - base_url: https://example.com
css_locator: .main-content css_locator: .content
exclude_selectors: exclude_selectors:
- .ads - .ads
- .navigation - .navigation
- footer max_depth: 2
allowed_paths: allowed_paths:
- /docs
- /blog - /blog
- /docs
exclude_paths: exclude_paths:
- /admin - /admin
file_name_prefix: example-docs output_alias: example
path_overrides: path_overrides:
- path: /special-page - path: /special-page
css_locator: .special-content css_locator: .special-content
exclude_selectors: exclude_selectors:
- .special-ads - .special-ads
# Output type for web scraping: 'single' or 'separate'
output_type: single output_type: single
# Rate limiting for web requests
requests_per_second: 1.0 requests_per_second: 1.0
burst_limit: 3 burst_limit: 3
``` ```
### Configuration Reference
| Field | Type | Description |
|-------|------|-------------|
| `file_extensions` | list | File extensions to include in file rollup |
| `ignore_paths` | list | Glob patterns for files/directories to skip |
| `code_generated_paths` | list | Glob patterns for auto-generated files |
| `sites` | list | Web scraping target configurations |
| `output_type` | string | `single` (one file) or `separate` (multiple files) |
| `requests_per_second` | float | Rate limit for web requests (default: 1.0) |
| `burst_limit` | int | Maximum burst size for rate limiting (default: 3) |
#### Site Configuration
| Field | Type | Description |
|-------|------|-------------|
| `base_url` | string | Starting URL for scraping (required) |
| `css_locator` | string | CSS selector for content extraction |
| `exclude_selectors` | list | CSS selectors for content to exclude |
| `allowed_paths` | list | URL paths allowed for scraping |
| `exclude_paths` | list | URL paths to skip |
| `file_name_prefix` | string | Prefix for output file names |
| `path_overrides` | list | Path-specific selector overrides |
## Examples ## Examples
### File Aggregation 1. Rollup files with default configuration:
```bash ```bash
# Rollup files using config file rollup files
rollup files ```
# Specify file types and ignore patterns 2. Web scraping with multiple URLs:
rollup files --types=go,js,ts --ignore="vendor/**,*_test.go"
# Rollup a specific directory ```bash
rollup files --path=/path/to/project rollup web --urls=https://example.com,https://another-example.com
``` ```
### Web Scraping 3. Generate a default configuration file:
```bash ```bash
# Scrape URLs from command line rollup generate
rollup web --urls=https://example.com/docs ```
# Scrape multiple URLs 4. Use a custom configuration file:
rollup web --urls=https://example.com,https://another.com
# Extract specific content with CSS selector ```bash
rollup web --urls=https://example.com --css=".article-content" rollup files --config=my-config.yml
```
# Exclude elements from scraped content 5. Web scraping with separate output files:
rollup web --urls=https://example.com --css=".content" --exclude=".ads,.sidebar"
# Output to separate files ```bash
rollup web --urls=https://example.com --output=separate rollup web --urls=https://example.com,https://another-example.com --output=separate
``` ```
### Configuration Generation 6. Rollup files with specific types and ignore patterns:
```bash ```bash
# Generate rollup.yml based on files in current directory rollup files --types=go,md --ignore=vendor/**,*_test.go
rollup generate ```
```
### Using Custom Config 7. Web scraping with depth and CSS selector:
```bash
```bash rollup web --urls=https://example.com --depth=2 --css=.main-content
rollup files --config=my-config.yml ```
rollup web --config=my-config.yml
```
## Output
### File Rollup Output
The `files` command generates a markdown file named `<project-name>-<timestamp>.rollup.md` containing all matched files:
```markdown
# File: src/main.go
```go
package main
// ... file contents
```
# File: docs/README.md (Code-generated, Read-only)
```md
// ... file contents
```
```
### Web Rollup Output
The `web` command generates markdown files from scraped content, with filenames based on the page title or URL.
## Contributing ## Contributing

View File

@@ -29,8 +29,6 @@ var webCmd = &cobra.Command{
Short: "Scrape main content from webpages and convert to Markdown", Short: "Scrape main content from webpages and convert to Markdown",
Long: `Scrape the main content from one or more webpages, ignoring navigational elements, ads, and other UI aspects. Convert the content to a well-structured Markdown file.`, Long: `Scrape the main content from one or more webpages, ignoring navigational elements, ads, and other UI aspects. Convert the content to a well-structured Markdown file.`,
PreRunE: func(cmd *cobra.Command, args []string) error { PreRunE: func(cmd *cobra.Command, args []string) error {
// Setup logger before initializing Playwright
scraper.SetupLogger(verbose)
// Initialize Playwright for web scraping // Initialize Playwright for web scraping
if err := scraper.InitPlaywright(); err != nil { if err := scraper.InitPlaywright(); err != nil {
return fmt.Errorf("failed to initialize Playwright: %w", err) return fmt.Errorf("failed to initialize Playwright: %w", err)
@@ -85,7 +83,6 @@ func runWeb(cmd *cobra.Command, args []string) error {
BaseURL: u, BaseURL: u,
CSSLocator: includeSelector, CSSLocator: includeSelector,
ExcludeSelectors: excludeSelectors, ExcludeSelectors: excludeSelectors,
AllowedPaths: []string{""},
} }
logger.Printf("URL %d configuration: BaseURL=%s, CSSLocator=%s", logger.Printf("URL %d configuration: BaseURL=%s, CSSLocator=%s",
i+1, u, includeSelector) i+1, u, includeSelector)