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

New blueprint: use wp cli to add a post with a featured image #27

Merged
merged 10 commits into from
Apr 19, 2024

Conversation

bph
Copy link
Collaborator

@bph bph commented Apr 16, 2024

The goal:

  • use the content from the markdown file
  • create a post
  • attach an image
  • display it as landing page.

This way one could create a playground instance with some test instructions right on the site.
There are a few challenges, I haven't figured out.
The write file step I tried both /wordpress/wp-content/uploads and /wp-content/uploads

Error message:
config-cb0d0260.js:631 Error: Could not write to "/wp-content/uploads/postcontent.md": There is no such file or directory OR the parent directory does not exist.

And I am not sure how to point wp-cli to the file to grab it and write it in a post.

The image part is also tricky.

Locally, I can use this
- wp media import ~/azblueprints/blueprints/wpcli-markdown/Select-storage-method.png --post_id=56 --title="Select your storage method" --featured_image

WordPress then created the media library directory, placed the file with all the image sizes and created db attachment post.

@bph bph marked this pull request as draft April 16, 2024 14:17
Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@bph bph changed the title New bluepring: use wp cli to create content from a markdown file. New blueprint: use wp cli to create content from a markdown file. Apr 16, 2024
@bph
Copy link
Collaborator Author

bph commented Apr 17, 2024

@adamziel Thank you so much for the correction of directories and the wp-cli command.
I changed the content from mark down to block notation as WordPress wouldn't convert the markdown.
And I added a wp-cli media command to add at featured image to the post. So cool that it works!

To test it before the merge use this link

@bph bph marked this pull request as ready for review April 17, 2024 16:11
@bph
Copy link
Collaborator Author

bph commented Apr 17, 2024

Here is a screenshot of the post created:
Screenshot 2024-04-17 at 18 12 05

@bph
Copy link
Collaborator Author

bph commented Apr 17, 2024

Nice going with the validity check on the PR!
It identifies a non-allowed directory (gutenbergtimes.com site) and suggested https://raw.githubusercontent.com/adamziel/blueprints/cli-markdown/ I added it but but that doesn't work...
That's why I added the test link in an earlier comment.

@bph bph changed the title New blueprint: use wp cli to create content from a markdown file. New blueprint: use wp cli to add a post with a featured image Apr 17, 2024
@bph
Copy link
Collaborator Author

bph commented Apr 18, 2024

Updated the directories to use 'https://raw.githubusercontent.com/adamziel/blueprints/trunk/blueprints/'

@bph
Copy link
Collaborator Author

bph commented Apr 18, 2024

Not quite sure how to solve this this failing check:
Screenshot 2024-04-18 at 08 27 06

@adamziel
Copy link
Contributor

adamziel commented Apr 19, 2024

@bph The problem with the https://raw.githubusercontent.com/adamziel/blueprints/trunk/blueprints/cli-markdown/postcontent.md URL is that it will work after merging, but it makes previewing the PR impossible as there isn't anything at that URL yet – it just return 404.

The URL pointing to your branch, https://raw.githubusercontent.com/adamziel/blueprints/cli-markdown/blueprints/wpcli-markdown/postcontent.md, returns the correct file. The problem now is – once we merge this PR and delete the branch, it will start returning 404.

I've reconciled this dualism recently with a repository automation that rewrites branch-specific URLs to trunk URLs. The automation verifies your PR only contains URLs pointing to your branch, and once we merge, it will update your Blueprint to point to trunk. I also documented this in CONTRIBUTING.md.

LMK what do you think, I haven't found a better solution yet.

@adamziel
Copy link
Contributor

I went ahead and updated the URLs in 30fb07d and 65e40ef. All checks are now green and the preview URL works.

@adamziel adamziel merged commit dd86280 into trunk Apr 19, 2024
2 checks passed
@adamziel adamziel deleted the cli-markdown branch April 19, 2024 15:15
@adamziel
Copy link
Contributor

I just confirmed that, after merging, the preview link in the Gallery document works as expected:

https://github.com/adamziel/blueprints/blob/trunk/GALLERY.md

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