Documentation
¶
Overview ¶
Package migrate provides tools for migrating from Python markata to markata-go.
Overview ¶
The migrate package helps users transition from Python markata by:
- Converting configuration files from Python markata format to markata-go format
- Migrating filter expressions to markata-go syntax
- Checking template compatibility with pongo2
- Generating detailed migration reports
Configuration Migration ¶
Configuration migration handles:
- Namespace changes ([markata] -> [markata-go])
- Key renames (glob_patterns -> patterns, etc.)
- Nav map to array conversion
- Feed filter expression migration
Filter Migration ¶
Filter expressions are migrated to handle:
- Boolean literal changes (published == 'True' -> published == True)
- `in` operator expansion (x in ['a', 'b'] -> x == 'a' or x == 'b')
- Operator spacing fixes (date<=today -> date <= today)
Usage ¶
Basic migration:
result, err := migrate.MigrateConfig("markata.toml", "markata-go.toml")
if err != nil {
log.Fatal(err)
}
fmt.Println(result.Report())
Filter migration:
migrated, changes := migrate.MigrateFilter("published == 'True'")
// migrated = "published == True"
// changes = ["Boolean literal: 'True' -> True"]
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Filter ¶
Filter migrates a Python markata filter expression to markata-go syntax. It returns the migrated expression and a list of changes made.
func ValidateFilter ¶
ValidateFilter validates a filter expression using the markata-go filter parser.
Types ¶
type CompareOptions ¶ added in v0.5.0
type CompareOptions struct {
// Extensions to compare (e.g., []string{".html"})
// If empty, all files are compared
Extensions []string
// IgnorePatterns are glob patterns to ignore
IgnorePatterns []string
}
CompareOptions configures the directory comparison.
func DefaultCompareOptions ¶ added in v0.5.0
func DefaultCompareOptions() CompareOptions
DefaultCompareOptions returns sensible defaults for comparing SSG output.
type CompareResult ¶ added in v0.5.0
type CompareResult struct {
// OldDir is the path to the old site directory
OldDir string
// NewDir is the path to the new site directory
NewDir string
// OldFiles is the list of files in the old directory
OldFiles []string
// NewFiles is the list of files in the new directory
NewFiles []string
// MissingInNew is the list of files in old but not in new
MissingInNew []string
// NewOnly is the list of files in new but not in old
NewOnly []string
// Common is the list of files present in both directories
Common []string
}
CompareResult contains the results of comparing two site directories.
func Compare ¶ added in v0.5.0
func Compare(oldDir, newDir string, opts CompareOptions) (*CompareResult, error)
Compare compares two directories and returns the differences.
func (*CompareResult) ExitCode ¶ added in v0.5.0
func (r *CompareResult) ExitCode() int
ExitCode returns the appropriate exit code for the comparison result. 0 = directories match, 1 = differences found.
func (*CompareResult) HasDifferences ¶ added in v0.5.0
func (r *CompareResult) HasDifferences() bool
HasDifferences returns true if there are any differences between directories.
func (*CompareResult) JSONReport ¶ added in v0.5.0
func (r *CompareResult) JSONReport() map[string]interface{}
JSONReport returns a JSON-friendly structure for programmatic use.
func (*CompareResult) Report ¶ added in v0.5.0
func (r *CompareResult) Report() string
Report generates a human-readable comparison report.
type ConfigChange ¶
type ConfigChange struct {
// Type is the change type: "namespace", "rename", "transform", "remove"
Type string
// Path is the config path (e.g., "markata.nav")
Path string
// OldValue is the original value
OldValue interface{}
// NewValue is the migrated value
NewValue interface{}
// Description explains the change
Description string
}
ConfigChange represents a single configuration change.
type FilterMigration ¶
type FilterMigration struct {
// Feed is the feed name this filter belongs to
Feed string
// Original is the original filter expression
Original string
// Migrated is the migrated filter expression
Migrated string
// Changes lists specific transformations applied
Changes []string
// Valid indicates if the migrated filter is valid
Valid bool
// Error contains any migration error
Error string
}
FilterMigration represents a filter expression migration.
type MigrationError ¶
type MigrationError struct {
// Category groups related errors
Category string
// Message describes the error
Message string
// Path is the config path or file path
Path string
// Fatal indicates if migration cannot continue
Fatal bool
}
MigrationError represents a blocking migration issue.
type MigrationResult ¶
type MigrationResult struct {
// InputFile is the source config file path
InputFile string
// OutputFile is the target config file path
OutputFile string
// Changes is the list of configuration changes made
Changes []ConfigChange
// FilterMigrations is the list of filter expression migrations
FilterMigrations []FilterMigration
// Warnings is the list of non-blocking issues
Warnings []Warning
// Errors is the list of blocking issues
Errors []MigrationError
// TemplateIssues is the list of template compatibility issues
TemplateIssues []TemplateIssue
// MigratedConfig is the resulting configuration (as generic map)
MigratedConfig map[string]interface{}
// Timestamp when migration was performed
Timestamp time.Time
}
MigrationResult contains the results of a migration operation.
func Config ¶
func Config(inputPath, outputPath string) (*MigrationResult, error)
Config migrates a Python markata config file to markata-go format. If outputPath is empty, it returns the result without writing.
func ConfigFromMap ¶
func ConfigFromMap(rawConfig map[string]interface{}) (*MigrationResult, error)
ConfigFromMap migrates a config map directly (useful for testing).
func (*MigrationResult) ExitCode ¶
func (r *MigrationResult) ExitCode() int
ExitCode returns the appropriate exit code for the migration result.
func (*MigrationResult) HasErrors ¶
func (r *MigrationResult) HasErrors() bool
HasErrors returns true if there are any migration errors.
func (*MigrationResult) HasWarnings ¶
func (r *MigrationResult) HasWarnings() bool
HasWarnings returns true if there are any warnings.
func (*MigrationResult) JSONReport ¶
func (r *MigrationResult) JSONReport() map[string]interface{}
JSONReport returns a JSON-friendly structure for programmatic use.
func (*MigrationResult) Report ¶
func (r *MigrationResult) Report() string
Report generates a human-readable migration report.
func (*MigrationResult) ShortReport ¶
func (r *MigrationResult) ShortReport() string
ShortReport generates a concise migration summary.
type TemplateIssue ¶
type TemplateIssue struct {
// File is the template file path
File string
// Line is the line number
Line int
// Issue describes the compatibility issue
Issue string
// Severity is "error", "warning", or "info"
Severity string
// Suggestion provides fix guidance
Suggestion string
}
TemplateIssue represents a template compatibility issue.
func CheckTemplates ¶
func CheckTemplates(templatesDir string) ([]TemplateIssue, error)
CheckTemplates scans a templates directory for compatibility issues.
type TemplateVariable ¶
TemplateVariable represents a template variable and its migration status.
func GetFilterMigrations ¶
func GetFilterMigrations() []TemplateVariable
GetFilterMigrations returns the list of filter migrations for templates.
func GetVariableMigrations ¶
func GetVariableMigrations() []TemplateVariable
GetVariableMigrations returns the list of variable migrations needed.
type Warning ¶
type Warning struct {
// Category groups related warnings
Category string // "config", "filter", "template", "plugin"
// Message describes the warning
Message string
// Path is the config path or file path
Path string
// Suggestion provides actionable guidance
Suggestion string
}
Warning represents a non-blocking migration issue.
func AnalyzeFilter ¶
AnalyzeFilter analyzes a filter expression and returns potential issues.