Documentation
¶
Overview ¶
Package content provides HTML page generation functionality.
Index ¶
Constants ¶
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 ¶
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)
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 ¶
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 ¶
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 (*Generator) GenerateRandomLink ¶
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 ¶
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.