Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for images #29

Merged
merged 1 commit into from
Mar 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ The site also works great when browsing the HTML files locally.

If it is the first time building the site or if you have updated the source SCSS you also need to run `npm install && npm run dev` to build the frontend assets.

#### Adding images
All media files in the `_media` directory will get copied to the `_site/media` directory upon build.
To reference an image in your Markdown, use the following syntax
```markdown
![Image Alt](../media/image.png "Image Title") # Note the relative path
```
Nested media directories are not yet supported.

#### Live preview
Use ` npm run watch` to watch the files for changes and start up a local dev server on port 3000 using Browsersync.
Expand Down
1 change: 1 addition & 0 deletions app/Actions/CreatesDefaultDirectories.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class CreatesDefaultDirectories
'_drafts',
'_pages',
'_posts',
'_media',
'_site',
'_docs',
'_site/posts',
Expand Down
10 changes: 10 additions & 0 deletions app/Commands/BuildStaticSiteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,17 @@ public function handle(): int
$this->warn('Running with high verbosity');
}

$this->line('Transferring Media Assets...');
$files = realpath('_media') . DIRECTORY_SEPARATOR . ("*.{png,svg,jpg,jpeg,gif,ico}");
$this->withProgressBar(glob($files, GLOB_BRACE), function ($filepath) {
if ($this->getOutput()->isVeryVerbose()) {
$this->line(' > Copying media file ' . basename($filepath) . ' to the output media directory');
}
copy($filepath, realpath('_site/media') . DIRECTORY_SEPARATOR . basename($filepath));
});

if (Features::hasBlogPosts()) {
$this->newLine(2);
$this->line('Creating Markdown Posts...');
$this->withProgressBar(CollectionService::getSourceSlugsOfModels(MarkdownPost::class), function ($slug) {
$this->debug((new StaticPageBuilder((new MarkdownPostParser($slug))->get(), true))->getDebugOutput());
Expand Down