content

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2025 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package content provides HTML page generation functionality.

Index

Constants

View Source
const (
	// Minimum and maximum number of links to generate per page.
	LinksPerPageMin = 5
	LinksPerPageMax = 10

	// Minimum and maximum length of randomly generated link strings.
	LengthOfLinksMin = 3
	LengthOfLinksMax = 20
)

Page generation constants.

Variables

This section is empty.

Functions

func WriteForm

func WriteForm(sb *strings.Builder, endpoint string)

WriteForm writes an HTML form element to the string builder.

The form uses the provided endpoint as its action URL and submits via GET method. The endpoint is HTML-escaped to prevent injection attacks. The form includes a text input field and a submit button.

Parameters:

  • sb: the string builder to write to
  • endpoint: the form action URL (will be HTML-escaped)
func WriteLink(sb *strings.Builder, address string)

WriteLink writes an HTML anchor tag to the string builder.

The link address is HTML-escaped to prevent injection attacks. The generated tag format is: <a href="...">...</a><br>

Parameters:

  • sb: the string builder to write to
  • address: the link address (will be HTML-escaped)

Types

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator handles HTML page generation with random links.

func NewGenerator

func NewGenerator(webpages []string, htmlTemplate, endpoint string, random *random.Source) *Generator

NewGenerator creates a new content generator.

Parameters:

  • webpages: wordlist entries for link generation (can be nil/empty for random strings)
  • htmlTemplate: optional HTML template with links to replace
  • endpoint: optional form submission endpoint
  • random: random number generator source

Returns a new Generator instance.

func (*Generator) GenerateNewPage

func (g *Generator) GenerateNewPage() string

GenerateNewPage creates a new HTML page from scratch with random links.

The number of links is randomly determined between LinksPerPageMin and LinksPerPageMax. Links are either selected from the wordlist (if available) or generated as random strings. If an endpoint is configured, a form is also included in the generated page.

Returns the complete HTML page as a string.

func (*Generator) GeneratePage

func (g *Generator) GeneratePage() string

GeneratePage generates an HTML page with random links.

If an HTML template is configured, it replaces all href attributes in <a> tags with random links while preserving the rest of the template structure. Otherwise, it generates a new HTML page from scratch with random links and optionally a form if an endpoint is configured.

Returns the generated HTML as a string.

func (g *Generator) GenerateRandomLink() string

GenerateRandomLink generates a random link address.

If a wordlist is available, it selects a random entry from the wordlist. Otherwise, it generates a random string using the configured character set with a length between LengthOfLinksMin and LengthOfLinksMax.

Uses thread-safe random number generation to prevent race conditions.

Returns the generated link address as a string.

func (*Generator) ReplaceLinksInHTML

func (g *Generator) ReplaceLinksInHTML(template string) string

ReplaceLinksInHTML replaces all href attributes in <a> tags with random links.

It uses pre-compiled regular expressions to find all anchor tags with href attributes (supporting both single and double quotes) and replaces the href value with a randomly generated link while preserving all other attributes and the tag structure. The replacement links are HTML-escaped.

Parameters:

  • template: the HTML template string to process

Returns the modified HTML string with replaced links.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL