Skip to content

Commit

Permalink
Keep assets dir
Browse files Browse the repository at this point in the history
  • Loading branch information
samwilson committed Jan 14, 2025
1 parent 5bdc789 commit 3290169
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 17 deletions.
5 changes: 2 additions & 3 deletions docs/content/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ The structure within that directory can be anything.

## Assets (stylesheets, scripts, etc.)

Every non-page file (CSS, JS, images, etc.) in the `content/` directory
All files (CSS, JS, images, etc.) in the `assets/` directory,
and all non-page files 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`.)

For more information, see the [Content documentation page](content.html).

## Output

All output is in the `output/` directory of a site.
Expand Down
4 changes: 2 additions & 2 deletions docs/content/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ these are explained on this page.
2. `flickr(photo_id)` – Get information about a [Flickr](https://www.flickr.com/) photo.
To use this, you need to set the `flickr.api_key` and `flickr.api_secret` values
in your site's `basildon.local.yaml` file.
3. `qrcode(text)` – Returns an asset-directory path to a QR code SVG file,
such as `/assets/8a482ae2afb51a1de85b7eb9087f7cc2.svg`.
3. `qrcode(text)` – Returns an output-directory path to a QR code SVG file,
such as `/qrcodes/8a482ae2afb51a1de85b7eb9087f7cc2.svg`.
For example: `<img src="{{ page.link(qrcode('string')) }}" />`
4. `wikidata(qid)` – Returns information about the given [Wikidata](https://www.wikidata.org/) item.
For example, `{{ wikidata('Q42').descriptions.en.value }}` will return something like "English writer and humorist".
Expand Down
37 changes: 27 additions & 10 deletions src/Command/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,26 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$template->render($page);
}

// Copy all non-page content files.
// Copy all other content files.
$files = new Finder();
$dir = $site->getDir();
$files->files()
->in($dir . '/content')
->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);
$this->copyFilesToOutput($dir, $files);

// Copy all assets.
// @TODO Add processing (LESS etc.).
$assetsDir = $dir . '/assets';
if (is_dir($assetsDir)) {
$assets = new Finder();
$assets->files()
->in($assetsDir)
->name('/.*\.(css|js|jpg|png|gif|svg|pdf)/');
$this->copyFilesToOutput($dir, $assets);
}

// Report build details.
$outDir = $site->getDir() . '/output/';
$outputSizeCmd = new Process(['du', '-h', '-s', $outDir]);
$outputSizeCmd->run();
Expand All @@ -143,4 +146,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int
]);
return 0;
}

/**
* @param string $dir Full filesystem path to the site directory.
* @param Finder $files The files to copy.
*/
private function copyFilesToOutput(string $dir, Finder $files): void
{
foreach ($files as $file) {
$fileRelativePath = substr($file->getRealPath(), strlen($dir . '/content'));
self::writeln('Copying content file: ' . $fileRelativePath);
Util::mkdir(dirname($dir . '/output' . $fileRelativePath));
copy($file->getRealPath(), $dir . '/output' . $fileRelativePath);
}
}
}
2 changes: 1 addition & 1 deletion src/Twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public function functionGetFeeds($feedUrls): ?array
}

/**
* @return string Relative URL string, of the form '/assets/qrcodes/hash.svg'.
* @return string Relative URL string, of the form '/qrcodes/hash.svg'.
*/
public function functionQrCode(string $text): string
{
Expand Down
2 changes: 1 addition & 1 deletion tests/TwigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function testQrCode(): void
$site = new Site(__DIR__ . '/test_site');
$twig = new Twig($this->db, $site, new Page($site, '/simple'));
$out = $twig->functionQrCode('Lorem');
self::assertSame('/assets/qrcodes/db6ff2ffe2df7b8cfc0d9542bdce27dc.svg', $out);
self::assertSame('/qrcodes/db6ff2ffe2df7b8cfc0d9542bdce27dc.svg', $out);
}

/**
Expand Down

0 comments on commit 3290169

Please sign in to comment.