Skip to content

Commit

Permalink
Remove assets directory
Browse files Browse the repository at this point in the history
  • Loading branch information
samwilson committed Jan 2, 2025
1 parent 9cc6ee5 commit 5bdc789
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 90 deletions.
114 changes: 56 additions & 58 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions docs/content/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ The structure within that directory can be anything.

*[Read more about Templates.](templates.html)*

## Assets (stylesheets and scripts)
## Assets (stylesheets, scripts, etc.)

Every stylesheet and script in the `assets/` directory
will be copied to `output/assets/`.
Every non-page file (CSS, JS, images, etc.) in the `content/` directory
will be copied to `output/`.
("Non-page" means anything with a file extension that
doesn't match the default as defined by the `ext` key in `basildon.yaml`.)

Images should be in the `content/` directory;
for more information, see the [Content documentation page](content.html).
For more information, see the [Content documentation page](content.html).

## Output

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion example/templates/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ site.title }}</title>
<link rel="stylesheet" href="{{ page.link('/assets/style.css') }}" />
<link rel="stylesheet" href="{{ page.link('/style.css') }}" />
</head>
<body>
<header class="site-header">
Expand Down
38 changes: 13 additions & 25 deletions src/Command/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,33 +114,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$template->render($page);
}

// Copy all other content files.
$images = new Finder();
// Copy all non-page content files.
$files = new Finder();
$dir = $site->getDir();
$images->files()
$files->files()
->in($dir . '/content')
->name('/.*\.(jpg|png|gif|svg|pdf)$/');
foreach ($images as $image) {
$assetRelativePath = substr($image->getRealPath(), strlen($dir . '/content'));
self::writeln('Image: ' . $assetRelativePath);
Util::mkdir(dirname($dir . '/output' . $assetRelativePath));
copy($image->getRealPath(), $dir . '/output' . $assetRelativePath);
}

// Copy all assets.
// @TODO Add processing (LESS etc.).
$assetsDir = $site->getDir() . '/assets';
if (is_dir($assetsDir)) {
$assets = new Finder();
$assets->files()
->in($dir . '/assets')
->name('/.*\.(css|js|jpg|png|gif|svg|pdf)/');
$assetsOutputDir = $dir . '/output/assets';
Util::mkdir($assetsOutputDir);
foreach ($assets as $asset) {
self::writeln('Asset: /assets/' . $asset->getFilename());
copy($asset->getRealPath(), $assetsOutputDir . '/' . $asset->getFilename());
}
->notName('*' . $site->getExt());
foreach ($files as $file) {
$fileRelativePath = substr($file->getRealPath(), strlen($dir . '/content'));
$srcPath = $file->getRealPath();
$destPath = $dir . '/output' . $fileRelativePath;
// if (filesize($srcPath) !== filesize($destPath) || md5_file($srcPath) !== md5_file($destPath) ) {
// }
self::writeln('Copying file: ' . $fileRelativePath);
Util::mkdir(dirname($destPath));
copy($srcPath, $destPath);
}

$outDir = $site->getDir() . '/output/';
Expand Down
2 changes: 1 addition & 1 deletion src/Twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ public function functionGetFeeds($feedUrls): ?array
public function functionQrCode(string $text): string
{
$qrFilename = md5($text) . '.svg';
$assetPath = '/assets/qrcodes/' . $qrFilename;
$assetPath = '/qrcodes/' . $qrFilename;
$filePath = $this->site->getDir() . '/output' . $assetPath;
$cachePath = $this->site->getDir() . '/cache/qrcodes/' . $qrFilename;
// If it's already been used in this run, nothing neds to be done.
Expand Down
Loading

0 comments on commit 5bdc789

Please sign in to comment.