git-it-write/includes/repo-config.php
Developer 7728f489bd feat: 本地文件模式 + 多仓库自动发现 (v3.0)
替换 Forgejo API 数据源为本地文件系统读取,支持 30+ 仓库自动发现。
新增 WP-Cron 定时同步、WP-CLI 命令、多站点支持、SEO 字段写入。
base_directory 为空时保留原 API 模式向后兼容。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-10 00:37:12 +08:00

62 lines
1.6 KiB
PHP

<?php
if( ! defined( 'ABSPATH' ) ) exit;
use Symfony\Component\Yaml\Yaml;
class GIW_Repo_Config{
private static $defaults = array(
'folder' => '',
'post_type' => 'post',
'category' => '',
'post_author' => 1,
'content_template' => '%%content%%',
'branch' => 'master',
);
/**
* Load .giw.yml from a repository root and merge with global defaults.
*
* @param string $repo_path Absolute path to the repo directory.
* @return array Merged configuration.
*/
public static function load( $repo_path ){
$global_settings = Git_It_Write::general_settings();
$defaults = self::$defaults;
// Override defaults with global settings where available.
if( !empty( $global_settings['default_post_type'] ) ){
$defaults['post_type'] = $global_settings['default_post_type'];
}
if( !empty( $global_settings['default_post_author'] ) ){
$defaults['post_author'] = (int) $global_settings['default_post_author'];
}
$config_file = rtrim( $repo_path, '/' ) . '/.giw.yml';
if( !is_readable( $config_file ) ){
return $defaults;
}
$yaml_content = file_get_contents( $config_file );
if( empty( $yaml_content ) ){
return $defaults;
}
$parsed = Yaml::parse( $yaml_content );
if( !is_array( $parsed ) ){
return $defaults;
}
return wp_parse_args( $parsed, $defaults );
}
}
?>