Skip to content

Commit 1241e3c

Browse files
committed
resolved conflict
Signed-off-by: bidi47 <bidi@apidemia.com>
2 parents 9923bdf + 14c135a commit 1241e3c

109 files changed

Lines changed: 203 additions & 148 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ php bin/doctrine-fixtures
5959
php bin/create-uploads-dir
6060
```
6161

62-
- `bin/doctrine-fixtures` loads `articles_cleaned.json` into the database, creating the `Post` entity (with its database-generated UUID) for the new article.
63-
- `bin/create-uploads-dir` must run *after* it - it resolves the post by slug to get that UUID, creates `public/uploads/article/{post-id}/`, and copies each image referenced in the `.html.twig` there from wherever it already lives under `public/uploads`.
62+
- `bin/doctrine-fixtures` loads `articles_cleaned.json` into the database, creating the `Post` entity for the new article.
63+
- `bin/create-uploads-dir` scans every `.md` file under `public/md-articles/` for `/uploads/article/filename.ext` references and, for any that aren't already present in `public/uploads/article/`, copies the file there from wherever it already lives under `public/uploads` (matched by filename). It doesn't touch the database.
6464

6565
`bin/doctrine-fixtures` isn't only for new articles - it matches existing posts by slug, so re-running it after editing any field on an existing entry (`post_title`, `excerpt`, `post_status`, etc.) updates that same `Post` row instead of creating a duplicate.
6666

‎bin/create-uploads-dir‎

Lines changed: 40 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -3,130 +3,99 @@
33

44
declare(strict_types=1);
55

6-
use Doctrine\ORM\EntityManager;
7-
use Light\Blog\Entity\Post;
8-
96
chdir(__DIR__ . '/../');
107

11-
require 'vendor/autoload.php';
12-
13-
$templatesDir = 'src/Blog/templates/page/blog-resource';
14-
$uploadsDir = 'public/uploads';
15-
$articleDir = $uploadsDir . '/article';
16-
$limit = null;
8+
$publicDir = 'public';
9+
$mdArticlesDir = $publicDir . '/md-articles';
10+
$articleDir = $publicDir . '/uploads/article';
1711

18-
if (isset($argv[1])) {
19-
if (! ctype_digit($argv[1]) || (int) $argv[1] < 1) {
20-
fwrite(STDERR, sprintf("Invalid file limit '%s'. Expected a positive integer.%s", $argv[1], PHP_EOL));
21-
exit(1);
22-
}
23-
$limit = (int) $argv[1];
12+
if (! is_dir($mdArticlesDir)) {
13+
fwrite(STDERR, sprintf("Directory '%s' not found%s", $mdArticlesDir, PHP_EOL));
14+
exit(1);
2415
}
2516

26-
if (! is_dir($templatesDir)) {
27-
fwrite(STDERR, sprintf("Directory '%s' not found%s", $templatesDir, PHP_EOL));
17+
if (! is_dir($articleDir) && ! mkdir($articleDir, 0775, true) && ! is_dir($articleDir)) {
18+
fwrite(STDERR, sprintf("Failed to create directory '%s'%s", $articleDir, PHP_EOL));
2819
exit(1);
2920
}
3021

31-
$container = require 'config/container.php';
32-
$entityManager = $container->get(EntityManager::class);
33-
$postRepository = $entityManager->getRepository(Post::class);
34-
3522
/**
36-
* Index every file currently under public/uploads (excluding the
37-
* uploads/article destination tree) by basename, so we can locate the
38-
* source file for each image referenced from a template.
39-
*
4023
* @return array<string, string>
4124
*/
42-
function indexUploadSources(string $uploadsDir, string $articleDir): array
25+
function indexUploadSources(string $publicDir, string $articleDir): array
4326
{
4427
$index = [];
4528

4629
$iterator = new RecursiveIteratorIterator(
47-
new RecursiveDirectoryIterator($uploadsDir, FilesystemIterator::SKIP_DOTS)
30+
new RecursiveDirectoryIterator($publicDir, FilesystemIterator::SKIP_DOTS)
4831
);
4932

5033
foreach ($iterator as $file) {
5134
if (! $file->isFile()) {
5235
continue;
5336
}
5437

55-
$path = $file->getPathname();
56-
if (str_starts_with($path, $articleDir . '/')) {
38+
$pathname = $file->getPathname();
39+
if (str_starts_with($pathname, $articleDir . '/')) {
5740
continue;
5841
}
5942

6043
$basename = $file->getFilename();
6144
if (! isset($index[$basename])) {
62-
$index[$basename] = $path;
45+
$index[$basename] = $pathname;
6346
}
6447
}
6548

6649
return $index;
6750
}
6851

69-
$sourceIndex = indexUploadSources($uploadsDir, $articleDir);
52+
/**
53+
* @return list<string>
54+
*/
55+
function extractArticleImageFilenames(string $contents): array
56+
{
57+
$pattern = '/uploads\/article\/([^\/)\]\s"\']+)/i';
7058

71-
// Matches the filename in: asset('uploads/article/' ~ article.id ~ '/filename.ext')
72-
$pattern = '/~\s*article\.id\s*~\s*\'\/([^\']+)\'/';
59+
preg_match_all($pattern, $contents, $matches);
7360

74-
$filesProcessed = 0;
75-
$dirsCreated = 0;
76-
$imagesCopied = 0;
77-
$imagesMissing = 0;
61+
return array_values(array_unique($matches[1]));
62+
}
7863

79-
$templateIterator = new RecursiveIteratorIterator(
80-
new RecursiveDirectoryIterator($templatesDir, FilesystemIterator::SKIP_DOTS)
81-
);
64+
$sourceIndex = indexUploadSources($publicDir, $articleDir);
8265

83-
foreach ($templateIterator as $file) {
84-
if ($limit !== null && $filesProcessed >= $limit) {
85-
break;
86-
}
66+
$mdFilesProcessed = 0;
67+
$imagesCopied = 0;
68+
$imagesMissing = 0;
69+
70+
$mdIterator = new RecursiveIteratorIterator(
71+
new RecursiveDirectoryIterator($mdArticlesDir, FilesystemIterator::SKIP_DOTS)
72+
);
8773

88-
if (! $file->isFile() || $file->getExtension() !== 'twig') {
74+
foreach ($mdIterator as $file) {
75+
if (! $file->isFile() || $file->getExtension() !== 'md') {
8976
continue;
9077
}
9178

92-
$path = $file->getPathname();
93-
$slug = preg_replace('/\.html\.twig$/', '', $file->getFilename());
94-
$contents = file_get_contents($path);
79+
$contents = file_get_contents($file->getPathname());
9580
if ($contents === false) {
9681
continue;
9782
}
9883

99-
preg_match_all($pattern, $contents, $matches);
100-
$filenames = array_unique($matches[1] ?? []);
84+
$filenames = extractArticleImageFilenames($contents);
10185
if ($filenames === []) {
10286
continue;
10387
}
10488

105-
$post = $postRepository->findOneBy(['slug' => $slug]);
106-
if ($post === null) {
107-
printf("No Post found for slug '%s' (%s), skipping%s", $slug, $path, PHP_EOL);
108-
continue;
109-
}
110-
111-
$filesProcessed++;
112-
113-
$targetDir = $articleDir . '/' . $post->getId()->toString();
114-
if (! is_dir($targetDir)) {
115-
if (! mkdir($targetDir, 0775, true) && ! is_dir($targetDir)) {
116-
fwrite(STDERR, sprintf("Failed to create directory '%s'%s", $targetDir, PHP_EOL));
117-
continue;
118-
}
119-
$dirsCreated++;
120-
}
89+
$mdFilesProcessed++;
12190

12291
foreach ($filenames as $filename) {
123-
$targetPath = $targetDir . '/' . $filename;
92+
$targetPath = $articleDir . '/' . $filename;
12493
if (file_exists($targetPath)) {
12594
continue;
12695
}
12796

12897
if (! isset($sourceIndex[$filename])) {
129-
printf("Source image '%s' not found for %s%s", $filename, $path, PHP_EOL);
98+
printf("Source image '%s' not found for %s%s", $filename, $file->getPathname(), PHP_EOL);
13099
$imagesMissing++;
131100
continue;
132101
}
@@ -141,11 +110,9 @@ foreach ($templateIterator as $file) {
141110
}
142111

143112
printf(
144-
"Done. %d template%s processed, %d director%s created, %d image%s copied, %d missing.%s",
145-
$filesProcessed,
146-
$filesProcessed === 1 ? '' : 's',
147-
$dirsCreated,
148-
$dirsCreated === 1 ? 'y' : 'ies',
113+
"Done. %d markdown file%s processed, %d image%s copied, %d missing.%s",
114+
$mdFilesProcessed,
115+
$mdFilesProcessed === 1 ? '' : 's',
149116
$imagesCopied,
150117
$imagesCopied === 1 ? '' : 's',
151118
$imagesMissing,

‎config/autoload/headers.global.php‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$llmsTxtLink = '</llms.txt>; rel="llms-txt", </llms-full.txt>; rel="llms-full-txt"';
6+
$serviceDocLink = static fn (string $url): string => sprintf('<%s>; rel="service-doc", ', $url) . $llmsTxtLink;
7+
8+
return [
9+
'dot_response_headers' => [
10+
'*' => [
11+
'X-Powered-By' => [
12+
'value' => 'Dotkernel',
13+
'overwrite' => true,
14+
],
15+
'X-Llms-Txt' => [
16+
'value' => '/llms.txt',
17+
'overwrite' => true,
18+
],
19+
'Link' => [
20+
'value' => $llmsTxtLink,
21+
'overwrite' => true,
22+
],
23+
],
24+
'app::index' => [
25+
'Link' => [
26+
'value' => $serviceDocLink('https://docs.dotkernel.org/'),
27+
'overwrite' => true,
28+
],
29+
],
30+
'page::api' => [
31+
'Link' => [
32+
'value' => $serviceDocLink('https://docs.dotkernel.org/api-documentation/'),
33+
'overwrite' => true,
34+
],
35+
],
36+
'page::admin' => [
37+
'Link' => [
38+
'value' => $serviceDocLink('https://docs.dotkernel.org/admin-documentation/'),
39+
'overwrite' => true,
40+
],
41+
],
42+
'page::queue' => [
43+
'Link' => [
44+
'value' => $serviceDocLink('https://docs.dotkernel.org/queue-documentation/'),
45+
'overwrite' => true,
46+
],
47+
],
48+
'page::light' => [
49+
'Link' => [
50+
'value' => $serviceDocLink('https://docs.dotkernel.org/light-documentation/'),
51+
'overwrite' => true,
52+
],
53+
],
54+
'page::frontend' => [
55+
'Link' => [
56+
'value' => $serviceDocLink('https://docs.dotkernel.org/frontend/'),
57+
'overwrite' => true,
58+
],
59+
],
60+
'page::wsl2' => [
61+
'Link' => [
62+
'value' => $serviceDocLink('https://docs.dotkernel.org/development/v2/terminal/'),
63+
'overwrite' => true,
64+
],
65+
],
66+
'page::architecture' => [
67+
'Link' => [
68+
'value' => $serviceDocLink('https://docs.dotkernel.org/api-documentation/'),
69+
'overwrite' => true,
70+
],
71+
],
72+
],
73+
];

‎config/autoload/local.php.dist‎

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,35 +47,19 @@ $app = [
4747
];
4848

4949
return [
50-
'application' => $app,
51-
'databases' => $databases,
52-
'dot_response_headers' => [
53-
'*' => [
54-
'X-Powered-By' => [
55-
'value' => $app['meta']['siteName'],
56-
'overwrite' => true,
57-
],
58-
'X-Llms-Txt' => [
59-
'value' => '/llms.txt',
60-
'overwrite' => true,
61-
],
62-
'Link' => [
63-
'value' => '</llms.txt>; rel="llms-txt", </llms-full.txt>; rel="llms-full-txt"',
64-
'overwrite' => true,
65-
],
66-
],
67-
],
68-
'doctrine' => [
50+
'application' => $app,
51+
'databases' => $databases,
52+
'doctrine' => [
6953
'connection' => [
7054
'orm_default' => [
7155
'params' => $databases['default'],
7256
],
7357
],
7458
],
75-
'feed' => [
59+
'feed' => [
7660
'path' => realpath(__DIR__ . '/../../public/feed.xml'),
7761
],
78-
'llms' => [
62+
'llms' => [
7963
'sourceDir' => realpath(__DIR__ . '/../../public/md-articles'),
8064
'outputFile' => realpath(__DIR__ . '/../../public/llms-full.txt'),
8165
// Markdown versions of the static pages, appended after the articles. Optional.

‎config/pipeline.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
// Register the routing middleware in the middleware pipeline.
4242
// This middleware registers the Mezzio\Router\RouteResult request attribute.
4343
$app->pipe(RouteMiddleware::class);
44-
$app->pipe(ResponseHeaderMiddleware::class);
4544

4645
// The following handle routing failures for common conditions:
4746
// - HEAD request but no routes answer that method
@@ -52,6 +51,7 @@
5251
$app->pipe(ImplicitHeadMiddleware::class);
5352
$app->pipe(ImplicitOptionsMiddleware::class);
5453
$app->pipe(MethodNotAllowedMiddleware::class);
54+
$app->pipe(ResponseHeaderMiddleware::class);
5555

5656
// Seed the UrlHelper with the routing results:
5757
$app->pipe(UrlHelperMiddleware::class);

‎package.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,10 @@
3535
"vite-plugin-css-injected-by-js": "^5.0.0",
3636
"vite-plugin-minify": "^3.0.0",
3737
"vite-plugin-static-copy": "^4.1.0"
38+
},
39+
"overrides": {
40+
"nanoid": "^3.3.18",
41+
"postcss": "^8.5.23",
42+
"svgo": "^4.1.0"
3843
}
3944
}

‎public/md-articles/architecture/configprovider-bootstrap-modern-php-applications.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ The ConfigProvider is automatically picked up by the framework during applicatio
8181

8282
Below you can see how Mezzio and Dotkernel merge and use ConfigProviders to build the middleware pipeline and dependencies.
8383

84-
![](/uploads/article/019f8a80-cc92-7277-92c8-c0e68d81615f/ConfigProvider2.png)
84+
![](/uploads/article/ConfigProvider2.png)
8585

8686
## Benefits
8787

‎public/md-articles/best-practice/aptana-set-svn-keywords.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ For example if you want to set the svn keyword property ***Id***:
1616

1717
1. In the file where you want to add the svn keyword property write **$Id$**
1818

19-
![](/uploads/article/019f8a80-cc86-73d9-a427-0621b2a55777/id-file-300x235.gif)
19+
![](/uploads/article/id-file-300x235.gif)
2020

2121
2. Right click on the file, then follow Team -> Set Property...**Note**: *Set Property...* will not be active if you haven't first added the file to SVN: *Team*->*Add to Version Controller*
2222

23-
![](/uploads/article/019f8a80-cc86-73d9-a427-0621b2a55777/set-property-300x152.gif)
23+
![](/uploads/article/set-property-300x152.gif)
2424

2525
3. Select **svn:keywords**, and write **Id** in the text field
2626

27-
![](/uploads/article/019f8a80-cc86-73d9-a427-0621b2a55777/svn-keywords-300x298.gif)
27+
![](/uploads/article/svn-keywords-300x298.gif)
2828

2929
When you make the SVN commit of the file, the *$Id$* keyword will be replaced with text in the format shown below:
3030

31-
![](/uploads/article/019f8a80-cc86-73d9-a427-0621b2a55777/id-file-svn-300x141.gif)
31+
![](/uploads/article/id-file-svn-300x141.gif)
3232

3333
## FAQ
3434

‎public/md-articles/best-practice/basic-security-in-dotkernel-headless-platform.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Let's take a practical view on software security in Dotkernel.
4848

4949
You should never trust that the user inputs correct data by passing it directly into your business logic. By defining the configuration for an input filter, you ensure that a field is both present, and of the correct type.
5050

51-
[Dotkernel API](https://www.dotkernel.org) makes use of [laminas/laminas-inputfilter](https://github.com/laminas/laminas-inputfilter) for this purpose.
51+
[Dotkernel API](https://www.dotkernel.com/api/) makes use of [laminas/laminas-inputfilter](https://github.com/laminas/laminas-inputfilter) for this purpose.
5252

5353
In addition to the above filtering, Dotkernel Admin also makes use of [laminas/laminas-form](https://github.com/laminas/laminas-form). laminas-form contains:
5454

‎public/md-articles/best-practice/svn-keywords-setup-in-php-ide-zend-studio.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ For **above** Proprieties , apply **only** to project folder, **NOT** recursive
6262
2. Select **All resources**.
6363
3. Check the **Use filtration by the resource name** and add **Mask:** *.php.
6464

65-
[![svn-add](/uploads/article/019f8a80-cc87-71b3-80b8-478826d88044/svn-add.jpg)](/uploads/2013/02/svn-add.jpg)
65+
[![svn-add](/uploads/article/svn-add.jpg)](/uploads/2013/02/svn-add.jpg)
6666

6767
## FAQ
6868

0 commit comments

Comments
 (0)