An open API service indexing awesome lists of open source software.

https://github.com/devnyxie/katsuragi

A Go toolkit offering utilities to efficiently extract favicons, links, descriptions, and titles, with support for LRU caching.
https://github.com/devnyxie/katsuragi

favicons go seo

Last synced: about 1 year ago
JSON representation

A Go toolkit offering utilities to efficiently extract favicons, links, descriptions, and titles, with support for LRU caching.

Awesome Lists containing this project

README

          

# katsuragi

![Go Build](https://github.com/devnyxie/katsuragi/actions/workflows/go.yml/badge.svg)
[![codecov](https://codecov.io/github/devnyxie/katsuragi/branch/main/graph/badge.svg?token=XFRMNJA858)](https://codecov.io/github/devnyxie/katsuragi)

A Go toolkit for web content processing, analysis, and SEO optimization, offering utilities to efficiently extract favicons, links, descriptions and titles.

> [!NOTE]
> Each method is thoroughly tested and optimized for performance, but the package is still in development and may contain unseen bugs. Please don't hesitate to report any issues you encounter!

**Table of Contents**

- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [Title](#title)
- [Description](#description)
- [Favicons](#favicons)
- [Links/Backlinks](#linksbacklinks)
- [Local Development](#local-development)
- [Testing](#testing)
- [Code Coverage](#code-coverage)
- [License](#license)

# Features

- LRU Caching
- Timeout
- User-Agent

# Installation

```bash
go get github.com/devnyxie/katsuragi
```

# Usage

## Title

The GetTitle() function currently supports the following title meta tags:

- `Title`
- ``
- ``

```go
import (
. "github.com/devnyxie/katsuragi"
)

func main() {
// Create a new fetcher with a timeout of 3 seconds and a cache capacity of 10
fetcher := NewFetcher(
&FetcherProps{
Timeout: 3000, // 3 seconds
CacheCap: 10, // 10 Network Requests will be cached
},
)

defer fetcher.ClearCache()

// Get website's title
title, err := fetcher.GetTitle("https://www.example.com")
}
```

## Description

The GetDescription() function currently supports the following description meta tags:

- ``
- ``
- ``

```go
...
// Get website's description
description, err := fetcher.GetDescription("https://www.example.com")
...
```

## Favicons

The GetFavicons() function currently supports the following favicon meta tags:

- ``
- ``
- ``
> Open Graph image (`og:image`) will be used only if both `og:image:width` and `og:image:height` are present and equal, forming a square image.

```go
...
// Get website's favicons
favicons, err := fetcher.GetFavicons("https://www.example.com")
// [https://www.example.com/favicon.ico, https://www.example.com/favicon.png]
...
```

## Links/Backlinks

The GetLinks() function searches for all `` tags in the HTML document and returns a slice of links.

Options:

- `Url` (required): The URL of the website to fetch.
- `Category` (optional): The category of links to fetch. Possible values are `internal`, `external`, and `all`. Default is `all`.

```go
// Get website's links
links, err := fetcher.GetLinks(GetLinksProps{
Url: "https://www.example.com",
Category: "external",
})
// [https://www.youtube.com/example, https://www.facebook.com/example]
```

# Local Development

## Testing

```bash
go test -v
```

## Code Coverage

```bash
# Generate coverage.out report, generate HTML report from coverage.out, and open the HTML report in the browser:
go test -coverprofile=coverage.out && go tool cover -html=coverage.out -o coverage.html && open coverage.html
```

# License

This project is licensed under the GNU General Public License (GPL). You can find the full text of the license [here](https://www.gnu.org/licenses/gpl-3.0.en.html).