Skip to content

Commit 16a081e

Browse files
feat: update lint workflow to use 'main' branch and enhance README with usage examples and features
1 parent 6c364f1 commit 16a081e

File tree

3 files changed

+86
-3
lines changed

3 files changed

+86
-3
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: lint
22
on:
33
push:
44
branches:
5-
- master
5+
- main
66
pull_request:
77

88
permissions:

README.md

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,85 @@
1-
# webinfo
2-
Extract metadata and structured information from web pages
1+
# webinfo -- Extract metadata and structured information from web pages
2+
3+
[![lint status](https://github.com/goark/webinfo/workflows/lint/badge.svg)](https://github.com/goark/webinfo/actions)
4+
[![GitHub license](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://raw.githubusercontent.com/goark/webinfo/master/LICENSE)
5+
[![GitHub release](http://img.shields.io/github/release/goark/webinfo.svg)](https://github.com/goark/webinfo/releases/latest)
6+
7+
webinfo is a small Go module that extracts common metadata from web pages and provides utilities
8+
to download representative images and create thumbnails.
9+
10+
**Quick overview**
11+
12+
- **Package**: `webinfo`
13+
- **Repository**: `github.com/goark/webinfo`
14+
- **Purpose**: fetch page metadata (title, description, canonical, image, etc.) and download images
15+
16+
**Features**
17+
18+
- Fetch page metadata with `Fetch` (handles encodings and meta tag precedence).
19+
- Download an image referenced by `Webinfo.ImageURL` using `(*Webinfo).DownloadImage`.
20+
- Create a thumbnail from the referenced image using `(*Webinfo).DownloadThumbnail`.
21+
22+
**Install**
23+
24+
Use Go modules (Go 1.25+ as used by the project):
25+
26+
```bash
27+
go get github.com/goark/webinfo@latest
28+
```
29+
30+
**Basic usage**
31+
32+
Example showing fetch and download thumbnail (error handling omitted for brevity):
33+
34+
```go
35+
package main
36+
37+
import (
38+
"context"
39+
"fmt"
40+
"github.com/goark/webinfo"
41+
)
42+
43+
func main() {
44+
ctx := context.Background()
45+
// Fetch metadata for a page (empty UA uses default)
46+
info, err := webinfo.Fetch(ctx, "https://example.com", "")
47+
if err != nil {
48+
fmt.Fprintln(os.Stderr, "error fetching webinfo:", err)
49+
panic(err)
50+
}
51+
52+
// Download thumbnail: width 150, to directory "thumbnails", permanent file
53+
thumbPath, err := info.DownloadThumbnail(ctx, "thumbnails", 150, false)
54+
if err != nil {
55+
panic(err)
56+
}
57+
fmt.Println("thumbnail saved:", thumbPath)
58+
}
59+
```
60+
61+
**API notes**
62+
63+
- `Fetch(ctx, url, userAgent)` — Parse and extract metadata. Pass an empty userAgent to use the module default.
64+
- `(*Webinfo).DownloadImage(ctx, destDir, temporary)` — Download the image in `Webinfo.ImageURL` and save it. If
65+
`temporary` is true (or `destDir` is empty), a temporary file is created.
66+
- `(*Webinfo).DownloadThumbnail(ctx, destDir, width, temporary)` — Download the referenced image and produce a
67+
thumbnail resized to `width` pixels (height is preserved by aspect ratio). If `destDir` is empty the method
68+
creates a temporary file; when `temporary` is false the thumbnail file is named based on the original image
69+
name with `-thums` appended before the extension.
70+
71+
**Error handling**
72+
73+
The package uses `github.com/goark/errs` for wrapping errors with contextual keys (e.g. `url`, `path`, `dir`).
74+
Callers should inspect returned errors accordingly.
75+
76+
**Tests & development**
77+
78+
- Run all tests: `go test ./...`
79+
- The repository includes `Taskfile.yml` tasks for common workflows; see that file for CI/test commands.
80+
81+
## Modules Requirement Graph
82+
83+
[![dependency.png](./dependency.png)](./dependency.png)
84+
85+
[webinfo]: https://github.com/goark/webinfo "goark/webinfo: Extract metadata and structured information from web pages"

dependency.png

97.2 KB
Loading

0 commit comments

Comments
 (0)