minor updates

This commit is contained in:
eyedeekay
2025-05-05 22:43:21 -04:00
parent edeeb85325
commit f2aa3b798c
3 changed files with 111 additions and 7 deletions

View File

@ -1,2 +1,67 @@
# go-gh-page
Generate github pages from the repository, keep the page in a branch, push to the branch
A tool that automatically generates GitHub Pages static websites from repository content. It converts your repository's Markdown files to HTML with a consistent layout, handles navigation, and preserves your documentation structure.
## Features
- Generates a complete static website from your repository's content
- Converts Markdown files to HTML with proper rendering
- Creates navigation structure based on your documentation
- Displays repository information (commits, contributors, license)
- Preserves images and handles relative links
- Supports custom templates and styles
- Includes GitHub Actions workflow for automatic deployment
## Installation
```bash
go install github.com/go-i2p/go-gh-page/cmd/github-site-gen@latest
```
## Usage
### Basic Usage
Generate a site for a GitHub repository:
```bash
github-site-gen -repo owner/repo-name -output ./site
```
### Command Line Options
| Flag | Description | Default |
|------|-------------|---------|
| `-repo` | GitHub repository in format 'owner/repo-name' | (Required) |
| `-output` | Output directory for generated site | `./output` |
| `-branch` | Branch to use | `main` |
| `-workdir` | Working directory for cloning | (Temporary directory) |
| `-githost` | Git host to use | `github.com` |
| `-main-template` | Path to custom main template | (Built-in template) |
| `-doc-template` | Path to custom documentation template | (Built-in template) |
| `-style-template` | Path to custom style template | (Built-in template) |
### Using with GitHub Actions
The repository includes a GitHub Actions workflow file that can automatically generate and deploy your documentation to GitHub Pages.
1. Copy the `.github/workflows/page.yml` file to your repository
2. Enable GitHub Pages on your repository (Settings → Pages → Source: gh-pages branch)
3. Customize the workflow as needed
The workflow runs hourly by default and on pushes to the main branch, automatically updating your GitHub Pages.
## Custom Templates
You can provide custom templates for different components of the generated site:
```bash
github-site-gen -repo owner/repo-name -output ./site \
-main-template path/to/main.html \
-doc-template path/to/doc.html \
-style-template path/to/style.css
```
## License
MIT License

View File

@ -105,6 +105,8 @@ func (g *Generator) GenerateSite() (*GenerationResult, error) {
// Prepare the list of documentation pages for navigation
var docsPages []utils.DocPage
var docsByDirectory = make(map[string][]utils.DocPage)
for path := range g.repoData.MarkdownFiles {
// Skip README as it's on the main page
if isReadmeFile(filepath.Base(path)) {
@ -117,13 +119,23 @@ func (g *Generator) GenerateSite() (*GenerationResult, error) {
}
outputPath := utils.GetOutputPath(path, "docs")
docsPages = append(docsPages, utils.DocPage{
docPage := utils.DocPage{
Title: title,
Path: outputPath,
})
}
// Add to main list
docsPages = append(docsPages, docPage)
// Add to directory-specific list for structured navigation
dirPath := filepath.Dir(path)
if dirPath == "." {
dirPath = "root"
}
docsByDirectory[dirPath] = append(docsByDirectory[dirPath], docPage)
}
// Sort docsPages by title for consistent navigation
// Sort docsPages by path for consistent navigation
utils.SortDocPagesByTitle(docsPages)
// Generate main index page
@ -132,6 +144,9 @@ func (g *Generator) GenerateSite() (*GenerationResult, error) {
}
// Generate documentation pages
processedCount := 0
var processedFiles []string
for path, content := range g.repoData.MarkdownFiles {
// Skip README as it's on the main page
if isReadmeFile(filepath.Base(path)) {
@ -142,9 +157,17 @@ func (g *Generator) GenerateSite() (*GenerationResult, error) {
return nil, fmt.Errorf("failed to generate doc page for %s: %w", path, err)
}
result.DocsCount++
processedFiles = append(processedFiles, path)
processedCount++
}
fmt.Printf("Processed %d markdown files:\n", processedCount)
for _, file := range processedFiles {
fmt.Printf(" - %s\n", file)
}
result.DocsCount = processedCount
// Generate site structure summary
var buffer bytes.Buffer
buffer.WriteString(g.outputDir + "/\n")
@ -254,6 +277,11 @@ func (g *Generator) generateDocPage(path, content string, docsPages []utils.DocP
currentDocsPages := make([]utils.DocPage, len(docsPages))
copy(currentDocsPages, docsPages)
outputPath := utils.GetOutputPath(path, "docs")
// Ensure output directory exists
outPath := filepath.Join(g.outputDir, outputPath)
if err := os.MkdirAll(filepath.Dir(outPath), 0755); err != nil {
return fmt.Errorf("failed to create directory for %s: %w", outPath, err)
}
for i := range currentDocsPages {
if currentDocsPages[i].Path == outputPath {
@ -287,7 +315,7 @@ func (g *Generator) generateDocPage(path, content string, docsPages []utils.DocP
}
// Ensure output directory exists
outPath := filepath.Join(g.outputDir, outputPath)
outPath = filepath.Join(g.outputDir, outputPath)
if err := os.MkdirAll(filepath.Dir(outPath), 0o755); err != nil {
return fmt.Errorf("failed to create directory for %s: %w", outPath, err)
}

View File

@ -106,7 +106,18 @@ func ProcessRelativeLinks(content, filePath, owner, repo string) string {
resolvedPath = resolvedPath[1:]
}
htmlPath := "../" + GetOutputPath(resolvedPath, "docs")
outputPath := GetOutputPath(resolvedPath, baseDir)
// Calculate the correct relative path based on the source and target file locations
htmlPath := outputPath
if baseDir != "." {
// If source file is in a subdirectory, calculate relative path
relPath, err := filepath.Rel(baseDir, filepath.Dir(resolvedPath))
if err == nil && relPath != "." {
// Need to adjust the link based on directory depth
htmlPath = filepath.Join("../", relPath, filepath.Base(htmlPath))
}
}
return "[" + linkText + "](" + htmlPath + anchor + ")"
}