...
This commit is contained in:
@@ -9,14 +9,16 @@ import os
|
||||
@[heap]
|
||||
pub struct Collection {
|
||||
pub mut:
|
||||
name string @[required]
|
||||
path pathlib.Path @[required]
|
||||
pages map[string]&Page
|
||||
images map[string]&File
|
||||
files map[string]&File
|
||||
atlas &Atlas @[skip; str: skip] // Reference to parent atlas for include resolution
|
||||
name string @[required]
|
||||
path pathlib.Path @[required]
|
||||
pages map[string]&Page
|
||||
images map[string]&File
|
||||
files map[string]&File
|
||||
atlas &Atlas @[skip; str: skip]
|
||||
errors []CollectionError
|
||||
error_cache map[string]bool // Track error hashes to avoid duplicates
|
||||
error_cache map[string]bool
|
||||
git_url string // NEW: URL to the git repository for editing
|
||||
git_branch string // NEW: Git branch for this collection
|
||||
}
|
||||
|
||||
@[params]
|
||||
|
||||
@@ -11,6 +11,33 @@ pub mut:
|
||||
redis bool = true
|
||||
}
|
||||
|
||||
// Generate edit URL for a page in the repository
|
||||
pub fn (p Page) get_edit_url() !string {
|
||||
col := p.collection
|
||||
if col.git_url == '' {
|
||||
return error('No git URL available for collection ${col.name}')
|
||||
}
|
||||
|
||||
// Remove .git suffix if present
|
||||
mut url := col.git_url
|
||||
if url.ends_with('.git') {
|
||||
url = url[0..url.len - 4]
|
||||
}
|
||||
|
||||
// Determine the provider and build appropriate edit URL
|
||||
if url.contains('github.com') {
|
||||
return '${url}/edit/${col.git_branch}/${p.path.name()}'
|
||||
} else if url.contains('gitlab.com') {
|
||||
return '${url}/-/edit/${col.git_branch}/${p.path.name()}'
|
||||
} else if url.contains('gitea') || url.contains('git.') {
|
||||
// Gitea-like interfaces
|
||||
return '${url}/src/branch/${col.git_branch}/${p.path.name()}'
|
||||
}
|
||||
|
||||
// Fallback: assume similar to GitHub
|
||||
return '${url}/edit/${col.git_branch}/${p.path.name()}'
|
||||
}
|
||||
|
||||
// Export all collections
|
||||
pub fn (mut a Atlas) export(args ExportArgs) ! {
|
||||
mut dest := pathlib.get_dir(path: args.destination, create: true)!
|
||||
@@ -29,10 +56,14 @@ pub fn (mut a Atlas) export(args ExportArgs) ! {
|
||||
include: args.include
|
||||
redis: args.redis
|
||||
)!
|
||||
|
||||
// Print errors for this collection if any
|
||||
|
||||
// Print collection info including git URL
|
||||
if col.has_errors() {
|
||||
col.print_errors()
|
||||
}
|
||||
|
||||
if col.git_url != '' {
|
||||
println('Collection ${col.name} source: ${col.git_url} (branch: ${col.git_branch})')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
module atlas
|
||||
|
||||
import incubaid.herolib.core.playbook { PlayBook }
|
||||
import incubaid.herolib.develop.gittools
|
||||
|
||||
// Play function to process HeroScript actions for Atlas
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
@@ -23,7 +24,17 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
new_atlas
|
||||
}
|
||||
|
||||
path := p.get('path')!
|
||||
mut path := p.get('path')!
|
||||
|
||||
// NEW: Support git URL as source
|
||||
mut git_url := p.get_default('git_url', '')!
|
||||
if git_url != '' {
|
||||
// Clone or get the repository using gittools
|
||||
mut gs := gittools.new(coderoot: p.get_default('git_root', '~/code')!)!
|
||||
mut repo := gs.get_repo(url: git_url)!
|
||||
path = repo.path()
|
||||
}
|
||||
|
||||
meta_path := p.get_default('meta_path', '')!
|
||||
atlas_instance.scan(path: path, meta_path: meta_path)!
|
||||
action.done = true
|
||||
|
||||
@@ -210,6 +210,48 @@ content := page.content(include: true)!
|
||||
content := page.content()!
|
||||
```
|
||||
|
||||
|
||||
## Git Integration
|
||||
|
||||
Atlas automatically detects the git repository URL for each collection and stores it for reference. This allows users to easily navigate to the source for editing.
|
||||
|
||||
### Automatic Detection
|
||||
|
||||
When scanning collections, Atlas walks up the directory tree to find the `.git` directory and captures:
|
||||
- **git_url**: The remote origin URL
|
||||
- **git_branch**: The current branch
|
||||
|
||||
### Scanning from Git URL
|
||||
|
||||
You can scan collections directly from a git repository:
|
||||
|
||||
```heroscript
|
||||
!!atlas.scan
|
||||
name: 'my_docs'
|
||||
git_url: 'https://github.com/myorg/docs.git'
|
||||
git_root: '~/code' // optional, defaults to ~/code
|
||||
```
|
||||
|
||||
The repository will be automatically cloned if it doesn't exist locally.
|
||||
|
||||
### Accessing Edit URLs
|
||||
|
||||
```v
|
||||
mut page := atlas.page_get('guides:intro')!
|
||||
edit_url := page.get_edit_url()!
|
||||
println('Edit at: ${edit_url}')
|
||||
// Output: Edit at: https://github.com/myorg/docs/edit/main/guides.md
|
||||
```
|
||||
|
||||
### Export with Source Information
|
||||
|
||||
When exporting, the git URL is displayed:
|
||||
|
||||
```
|
||||
Collection guides source: https://github.com/myorg/docs.git (branch: main)
|
||||
```
|
||||
|
||||
This allows published documentation to link back to the source repository for contributions.
|
||||
## Links
|
||||
|
||||
Atlas supports standard Markdown links with several formats for referencing pages within collections.
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
module atlas
|
||||
|
||||
import incubaid.herolib.core.pathlib
|
||||
import incubaid.herolib.data.paramsparser
|
||||
import incubaid.herolib.core.texttools
|
||||
import incubaid.herolib.core.base
|
||||
import incubaid.herolib.develop.gittools
|
||||
import incubaid.herolib.data.paramsparser
|
||||
import os
|
||||
|
||||
// Scan a directory for collections
|
||||
@@ -30,6 +32,33 @@ fn (mut a Atlas) scan_directory(mut dir pathlib.Path) ! {
|
||||
}
|
||||
}
|
||||
|
||||
// Detect git repository URL for a collection
|
||||
fn (mut c Collection) detect_git_url() ! {
|
||||
mut current_path := c.path
|
||||
|
||||
// Walk up directory tree to find .git
|
||||
mut git_repo := current_path.parent_find('.git') or {
|
||||
// No git repo found
|
||||
return
|
||||
}
|
||||
|
||||
if git_repo.path == '' {
|
||||
return
|
||||
}
|
||||
|
||||
// Get git origin URL
|
||||
origin_url := os.execute('cd ${git_repo.path} && git config --get remote.origin.url')
|
||||
if origin_url.exit_code == 0 {
|
||||
c.git_url = origin_url.output.trim_space()
|
||||
}
|
||||
|
||||
// Get current branch
|
||||
branch_result := os.execute('cd ${git_repo.path} && git branch --show-current')
|
||||
if branch_result.exit_code == 0 {
|
||||
c.git_branch = branch_result.output.trim_space()
|
||||
}
|
||||
}
|
||||
|
||||
// Check if directory is a collection
|
||||
fn is_collection_dir(path pathlib.Path) bool {
|
||||
return path.file_exists('.collection')
|
||||
@@ -60,6 +89,11 @@ fn should_skip_dir(entry pathlib.Path) bool {
|
||||
// Scan collection directory for files
|
||||
fn (mut c Collection) scan() ! {
|
||||
c.scan_path(mut c.path)!
|
||||
// Detect git URL after scanning
|
||||
c.detect_git_url() or {
|
||||
// Log but don't fail if git detection fails
|
||||
// console.print_debug('Could not detect git URL for collection ${c.name}: ${err}')
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut c Collection) scan_path(mut dir pathlib.Path) ! {
|
||||
|
||||
Reference in New Issue
Block a user