new_post.sh: decide a solution for last date situation #1

Closed
opened 2024-05-08 20:07:06 +02:00 by exopedro · 0 comments
Owner

Regarding the correction I had to do to fix the date 03d4ec8f78

Assuming I am not wrong, I suspect that what happened is that the new_post.sh script was called two times

And that would confirm my suspiction (it is assuming that the already rendered publication might be there)

current_number="$(echo "${publications}" | grep -v "${today}" | wc -l)"

On first time, it successfully got the latest date from the publications directory (but see appendix 1)

On the second time, last publication, is the same publication I am rendering now, and that's how the last date becomes today

I see that for second time it should happen an additional validation:

Get the date from the yaml front matter, particularly date, and compare if the file already exists in posts dir. If it exists you might want to stop and ask the user to delete it to continue, or delete it (hence override with the new post)

In fact, using the var from the yaml front matter, it might be better to get the today from the date yaml var instead of this command

today="$(date +"%Y-%m-%d")"

year and month are vars not used (by the way, you can inject a specific date to date shell command, and parse that parts too, -d argument)

Other solution might apply, because there is a lot of ways to do this... let's decide something

Appendix 1

another problem maybe related to freebsd vs linux? In my system that find query gives it to me unsorted, and that magic would not work in my case:

last_date="$(echo "${publications}" | tail -n 1 | cut -d '/' -f 2)"

[2024-05-08 Wed 19:59:30] $ find posts/ -maxdepth 1 -mindepth 1 -type d
posts/2024-03-06
posts/2024-05-08
posts/2024-04-10
posts/2024-03-13
[2024-05-08 Wed 19:59:32] $ find posts/ -maxdepth 1 -mindepth 1 -type d | sort
posts/2024-03-06
posts/2024-03-13
posts/2024-04-10
posts/2024-05-08
Regarding the correction I had to do to fix the date https://farga.exo.cat/exo/eXOfasia/commit/03d4ec8f780526d3928d507c8f75e3fd3b212016 Assuming I am not wrong, I suspect that what happened is that the `new_post.sh` script was called two times And that would confirm my suspiction (it is assuming that the already rendered publication might be there) https://farga.exo.cat/exo/eXOfasia/src/commit/03d4ec8f780526d3928d507c8f75e3fd3b212016/new_post.sh#L15 On first time, it successfully got the latest date from the publications directory (but see appendix 1) On the second time, last publication, is the same publication I am rendering now, and that's how the last date becomes today I see that for second time it should happen an additional validation: Get the date from the `yaml front matter`, particularly `date`, and compare if the file already exists in posts dir. If it exists you might want to stop and ask the user to delete it to continue, or delete it (hence override with the new post) In fact, using the var from the `yaml front matter`, it might be better to get the today from the `date` yaml var instead of this command https://farga.exo.cat/exo/eXOfasia/src/commit/03d4ec8f780526d3928d507c8f75e3fd3b212016/new_post.sh#L14 `year` and `month` are vars not used (by the way, you can inject a specific date to `date` shell command, and parse that parts too, `-d` argument) Other solution might apply, because there is a lot of ways to do this... let's decide something ## Appendix 1 another problem maybe related to freebsd vs linux? In my system that `find` query gives it to me unsorted, and that magic would not work in my case: https://farga.exo.cat/exo/eXOfasia/src/commit/03d4ec8f780526d3928d507c8f75e3fd3b212016/new_post.sh#L13 ``` [2024-05-08 Wed 19:59:30] $ find posts/ -maxdepth 1 -mindepth 1 -type d posts/2024-03-06 posts/2024-05-08 posts/2024-04-10 posts/2024-03-13 [2024-05-08 Wed 19:59:32] $ find posts/ -maxdepth 1 -mindepth 1 -type d | sort posts/2024-03-06 posts/2024-03-13 posts/2024-04-10 posts/2024-05-08 ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: exo/eXOfasia#1
No description provided.