定制 aaronfrancis/docsync 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

aaronfrancis/docsync

Composer 安装命令:

composer require aaronfrancis/docsync

包简介

Sync documentation from GitHub repositories and serve them in your Laravel application

README 文档

README

Latest Version on Packagist Tests Total Downloads PHP Version License

Sync documentation from GitHub repositories and serve them in your Laravel application.

Features

  • Git sparse checkout - Efficiently clones only the docs folder from repositories
  • Markdown parsing - CommonMark + GFM with Torchlight syntax highlighting
  • Navigation generation - Builds navigation trees from _meta.json files
  • Table of contents - Automatically extracts headings for TOC
  • Pagination - Previous/next page navigation
  • Caching - Built-in caching for production performance
  • Filament integration - Optional admin panel for managing documentation projects

Requirements

  • PHP 8.2+
  • Laravel 11 or 12
  • Torchlight account (for syntax highlighting)

Installation

composer require aaronfrancis/docsync

Publish the configuration and migration:

php artisan vendor:publish --tag=docsync-config
php artisan vendor:publish --tag=docsync-migrations
php artisan migrate

Configuration

// config/docsync.php

return [
    // Where synced docs are stored
    'storage_path' => storage_path('app/docs'),

    // Config key for GitHub token (for private repos)
    'github_token_key' => 'services.github.token',

    // Cache settings
    'cache' => [
        'enabled' => true,
        'ttl' => 3600, // 1 hour
    ],
];

Set your GitHub token in config/services.php:

'github' => [
    'token' => env('GITHUB_TOKEN'),
],

Usage

Creating Documentation Projects

Projects are stored in the database. Create them however you prefer:

use AaronFrancis\DocSync\Models\DocumentationProject;

DocumentationProject::create([
    'slug' => 'my-package',
    'name' => 'My Package',
    'description' => 'Documentation for my package',
    'repository_url' => 'https://github.com/org/repo',
    'branch' => 'main',
    'docs_path' => 'docs',
    'sort_order' => 0,
    'is_active' => true,
]);

Syncing Documentation

Sync all active projects:

php artisan docs:sync

Sync a specific project:

php artisan docs:sync --project=my-package

Scheduling Syncs

Add to your routes/console.php:

use Illuminate\Support\Facades\Schedule;

Schedule::command('docs:sync')
    ->hourly()
    ->withoutOverlapping()
    ->runInBackground();

Using the Service

use AaronFrancis\DocSync\Facades\DocSync;
// or inject: AaronFrancis\DocSync\Services\DocumentationService

// Get all packages
$packages = DocSync::getPackages();

// Get a single package
$package = DocSync::getPackage('my-package');

// Get navigation tree
$navigation = DocSync::getNavigation('my-package');

// Get a page
$page = DocSync::getPage('my-package', 'getting-started');

// Get table of contents from HTML
$toc = DocSync::getTableOfContents($page['content']);

// Get pagination (previous/next)
$pagination = DocSync::getPagination('my-package', 'getting-started');

// Get next steps (upcoming pages with descriptions)
$nextSteps = DocSync::getNextSteps('my-package', 'getting-started', 3);

// Clear cache
DocSync::clearCache(); // all
DocSync::clearCache('my-package'); // specific package

Documentation Structure

Your repository should have a docs folder (or whatever you configure) with:

docs/
├── _meta.json      # Navigation structure
├── index.md        # Landing page
├── getting-started.md
└── advanced/
    └── configuration.md

The _meta.json defines navigation:

{
  "pages": [
    { "slug": "index", "title": "Introduction" },
    { "slug": "getting-started", "title": "Getting Started" },
    {
      "slug": "advanced",
      "title": "Advanced",
      "children": [
        { "slug": "configuration", "title": "Configuration" }
      ]
    }
  ]
}

Markdown files support frontmatter:

---
title: Getting Started
description: Learn how to get started with the package
---

# Getting Started

Your content here...

Filament Integration

If you're using Filament, register the resource in your panel provider:

use AaronFrancis\DocSync\Filament\Resources\DocumentationProjectResource;

public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->resources([
            DocumentationProjectResource::class,
        ]);
}

This provides a full CRUD interface for managing documentation projects with sync actions.

Building Your Frontend

This package handles syncing and parsing—you build the frontend. Here's a basic controller example:

use AaronFrancis\DocSync\Facades\DocSync;

class DocsController extends Controller
{
    public function index()
    {
        return view('docs.index', [
            'packages' => DocSync::getPackages(),
        ]);
    }

    public function show(string $package, ?string $slug = null)
    {
        $currentPackage = DocSync::getPackage($package);
        abort_unless($currentPackage, 404);

        $page = DocSync::getPage($package, $slug);
        abort_unless($page, 404);

        return view('docs.show', [
            'page' => $page,
            'navigation' => DocSync::getNavigation($package),
            'toc' => DocSync::getTableOfContents($page['content']),
            'pagination' => DocSync::getPagination($package, $slug),
            'packages' => DocSync::getPackages(),
            'currentPackage' => $currentPackage,
        ]);
    }
}

Testing

composer test

Code Style

composer format

License

MIT License. See LICENSE for details.

aaronfrancis/docsync 适用场景与选型建议

aaronfrancis/docsync 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 898 次下载、GitHub Stars 达 3, 最近一次更新时间为 2025 年 12 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「documentation」 「markdown」 「sync」 「github」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 aaronfrancis/docsync 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 aaronfrancis/docsync 我们能提供哪些服务?
定制开发 / 二次开发

基于 aaronfrancis/docsync 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 898
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 20
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-30