Skip to content

Commit 60894b5

Browse files
committed
Initial commit: First version of LiteDocs
0 parents  commit 60894b5

28 files changed

+1247
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/vendor
2+
/site
3+
.idea
4+
.vscode
5+
litedocs.phar
6+
composer.lock

bin/litedocs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
declare(strict_types=1);
5+
6+
require dirname(__DIR__) . '/vendor/autoload.php';
7+
8+
use LiteDocs\Command\BuildCommand;
9+
use Symfony\Component\Console\Application;
10+
11+
$application = new Application('LiteDocs', '1.0.0');
12+
13+
$application->addCommand(new BuildCommand());
14+
15+
$application->run();

composer.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "ezar101/litedocs",
3+
"description": "A lightweight static site generator.",
4+
"version": "1.0.0",
5+
"license": "MIT",
6+
"type": "project",
7+
"autoload": {
8+
"psr-4": {
9+
"LiteDocs\\": "src/"
10+
}
11+
},
12+
"authors": [
13+
{
14+
"name": "Ezar Affandi",
15+
"email": "salez.ea@gmail.com"
16+
}
17+
],
18+
"require": {
19+
"php": ">=8.4",
20+
"symfony/console": "^8.0",
21+
"symfony/yaml": "^8.0",
22+
"symfony/filesystem": "^8.0",
23+
"symfony/event-dispatcher": "^8.0",
24+
"symfony/options-resolver": "^8.0",
25+
"twig/twig": "^3.22",
26+
"league/commonmark": "^2.8",
27+
"symfony/finder": "^8.0"
28+
},
29+
"bin": [
30+
"bin/litedocs"
31+
],
32+
"config": {
33+
"sort-packages": true
34+
}
35+
}

config/nav.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
en:
2+
- Home: index.md

config/plugins.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
LiteDocs\Plugin\ReadingTimePlugin: ~
2+
3+
LiteDocs\Plugin\TableOfContentsPlugin: ~
4+
5+
LiteDocs\Plugin\SyntaxHighlightPlugin: ~
6+
7+
LiteDocs\Plugin\SearchPlugin: ~

docs/en/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Welcome to LiteDocs
2+
3+
This is a static site generator made in **PHP**.

litedocs.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
site_name: 'My Docs'
2+
theme: 'lite'
3+
4+
languages:
5+
en: English
6+
7+
nav: 'config/nav.yaml'
8+
plugins: 'config/plugins.yaml'

src/Command/BuildCommand.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace LiteDocs\Command;
6+
7+
use LiteDocs\Core\Kernel;
8+
use Symfony\Component\Console\Attribute\AsCommand;
9+
use Symfony\Component\Console\Command\Command;
10+
use Symfony\Component\Console\Input\InputInterface;
11+
use Symfony\Component\Console\Output\OutputInterface;
12+
use Symfony\Component\Console\Style\SymfonyStyle;
13+
use Symfony\Component\EventDispatcher\EventDispatcher;
14+
15+
#[AsCommand(
16+
name: 'build',
17+
description: 'Build the documentation as a static HTML site.',
18+
)]
19+
class BuildCommand extends Command
20+
{
21+
protected function execute(InputInterface $input, OutputInterface $output): int
22+
{
23+
$io = new SymfonyStyle($input, $output);
24+
$projectDir = getcwd(); // User's current directory
25+
26+
$dispatcher = new EventDispatcher();
27+
28+
try {
29+
$kernel = new Kernel($projectDir, $dispatcher);
30+
$kernel->boot();
31+
32+
$io->title('LiteDocs Builder');
33+
$io->text('Configuration loaded.');
34+
35+
$kernel->build();
36+
37+
$io->success('Build complete!');
38+
39+
return Command::SUCCESS;
40+
} catch (\Exception $e) {
41+
$io->error($e->getMessage());
42+
43+
return Command::FAILURE;
44+
}
45+
}
46+
}

src/Config/Configuration.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace LiteDocs\Config;
6+
7+
use Symfony\Component\OptionsResolver\Options;
8+
use Symfony\Component\OptionsResolver\OptionsResolver;
9+
10+
class Configuration
11+
{
12+
public function resolve(array $config): array
13+
{
14+
$resolver = new OptionsResolver();
15+
16+
$resolver->setDefaults([
17+
'site_name' => 'My LiteDocs',
18+
'site_url' => null,
19+
'docs_dir' => 'docs',
20+
'site_dir' => 'site',
21+
'theme' => ['name' => 'lite'],
22+
'plugins' => [],
23+
'nav' => null,
24+
'languages' => [],
25+
'logo' => null,
26+
'favicon' => null,
27+
]);
28+
29+
$resolver->setAllowedTypes('site_name', 'string');
30+
$resolver->setAllowedTypes('site_url', ['null', 'string']);
31+
$resolver->setAllowedTypes('docs_dir', 'string');
32+
$resolver->setAllowedTypes('site_dir', 'string');
33+
$resolver->setAllowedTypes('theme', ['string', 'array']);
34+
$resolver->setAllowedTypes('plugins', 'array');
35+
$resolver->setAllowedTypes('nav', ['null', 'array']);
36+
$resolver->setAllowedTypes('languages', 'array');
37+
$resolver->setAllowedTypes('logo', ['null', 'string']);
38+
$resolver->setAllowedTypes('favicon', ['null', 'string']);
39+
40+
$resolver->setNormalizer('theme', function (Options $options, string | array $value): array {
41+
if (is_string($value)) {
42+
return ['name' => $value];
43+
}
44+
45+
return $value;
46+
});
47+
48+
return $resolver->resolve($config);
49+
}
50+
}

0 commit comments

Comments
 (0)