Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use the Posts found in './bin' instead of the root directory#10

Merged
tesar-tech merged 2 commits into
BlazorStatic:masterfrom
junovell:PostsPathChange
May 14, 2024
Merged

Use the Posts found in './bin' instead of the root directory#10
tesar-tech merged 2 commits into
BlazorStatic:masterfrom
junovell:PostsPathChange

Conversation

@junovell

Copy link
Copy Markdown
Contributor

change the path where the Posts are searched for, from the root directory of the project to where the assembly of the project is.

original: src/Content/**
new: src/bin/**/netX.0/Content/**

benefits: allow the user to update the Posts pragmatically before parsing them without tampering with the original files.

this also means that the .csproj file must contain the following lines:

<ItemGroup>
  <None Update="Content/**/*">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  </None>
</ItemGroup>

junovell and others added 2 commits May 13, 2024 11:02
these are the files copied on project build, which allows the user to update the posts pragmatically before parsing them without tampering with the original files
@tesar-tech

Copy link
Copy Markdown
Collaborator

Hm. Interesting.
If you would ask me before I would tell you that it is already happening (that's why the copy content is already there). But the Directory.GetFiles is really getting files from the root directory.

There is just one issue with modifying the blog files -> When you publish your app, the "bin" folder becomes the "project" root folder and the files in Content is just one. So when you change it, it will stay changed.

What is exactly the use case when you need to modify the files? Because maybe there is a better way.

Thanks for you PRs, appreciate that.

@junovell

Copy link
Copy Markdown
Contributor Author

I honestly didn't think much about it, I saw that the example website already has those lines added but noticed the code doesn't make use of them.

A use case I can think of is to have the posts' read time calculated dynamically instead of having it hardcoded in the posts' front matter, or being able to upload the images in a post to a CDN while leaving the root files use the local copies for offline editing.

@tesar-tech

Copy link
Copy Markdown
Collaborator

That sounds like a job for opt.AfterBlogParsedAndAddedAction. For example here I am doing exactly that - changing path for the images.

The posts live in memory for a brief period of time and you can can change them however you like..

@tesar-tech tesar-tech merged commit 4a3f151 into BlazorStatic:master May 14, 2024
@junovell

Copy link
Copy Markdown
Contributor Author

the issue with opt.AfterBlogParsedAndAddedAction is that, as the name implies, comes after the blogs were parsed which makes it hard, for example, to count the words in a blog and calculate the reading time since you'll have to parse the html and extract it's content which is extra work

@junovell junovell deleted the PostsPathChange branch May 15, 2024 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants