fixer

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package fixer provides functionality to automatically fix redirect URLs in markdown files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetailedSummary

func DetailedSummary(results []FixResult) string

DetailedSummary returns a detailed summary showing each change.

func Summary

func Summary(results []FixResult) string

Summary returns a formatted summary of fix results.

Types

type FileChanges

type FileChanges struct {
	FilePath   string
	Fixes      []Fix
	TotalFixes int // Total number of replacements (accounting for occurrences)
}

FileChanges groups all fixes for a single file.

type Fix

type Fix struct {
	FilePath    string // File containing the URL
	OldURL      string // Original URL (redirect source)
	NewURL      string // Final URL (redirect destination)
	RefName     string // Reference name if IsRefDef (e.g., "myref" in [myref]: url)
	Line        int    // Line number where the URL appears
	Occurrences int    // How many times this exact URL appears in the file
	LinkType    parser.LinkType
	RefUsages   int  // How many places use this reference
	IsRefDef    bool // Is this a reference definition line?
}

Fix represents a single URL replacement to be made.

type FixResult

type FixResult struct {
	Error       error
	FilePath    string
	ChangedURLs []URLChange
	Applied     int
	Skipped     int
}

FixResult represents the outcome of applying fixes to a file.

type Fixer

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

Fixer handles URL replacement in markdown files.

func New

func New() *Fixer

New creates a new Fixer instance.

func (*Fixer) ApplyAll

func (f *Fixer) ApplyAll(changes []FileChanges) []FixResult

ApplyAll applies fixes to all files and returns results.

func (*Fixer) ApplyToFile

func (*Fixer) ApplyToFile(fc FileChanges) (*FixResult, error)

ApplyToFile applies all fixes to a single file.

func (*Fixer) FindFixes

func (f *Fixer) FindFixes(results []checker.Result) []FileChanges

FindFixes analyzes check results and returns fixable items grouped by file. Only redirects with a successful final destination (200) are considered fixable.

func (*Fixer) Preview

func (*Fixer) Preview(changes []FileChanges) string

Preview returns a formatted string showing what changes would be made.

func (f *Fixer) SetParserLinks(links []parser.Link)

SetParserLinks provides the original parser links for reference detection.

type URLChange

type URLChange struct {
	OldURL string
	NewURL string
	Line   int
}

URLChange represents a single URL that was changed.

Jump to

Keyboard shortcuts

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