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

Jekyll: Fix many bugs, add new features #506

Merged
merged 19 commits into from
Jul 9, 2022

Conversation

markstos
Copy link
Contributor

@markstos markstos commented Jun 5, 2022

UPDATE: This PR was originally about the narrow scope of fixing the bug below. But I soon ran into a number other bugs and missing features that affected the same parts of the code. It quickly became not feasible to submit separate PRs for them, as many would overlap would conflict, so this PR collects all the fixes I've made. Looking at the individual commits will provide context for each change.


Bug: "Should import _posts, not "posts""

The Jekyll docs are clear that posts go in "_posts" (with an
underscore):

https://jekyllrb.com/docs/structure/

While "posts" (no underscore) may be the the name of an output directory
with rendered HTML.

Because HTML is also valid as an impout format, importing "posts" is
no longer supported to avoid confusion.

@markstos markstos changed the title y Jekyll: import _posts, not "posts" Jun 5, 2022
@markstos markstos force-pushed the rename-posts branch 2 times, most recently from 6fc40f9 to 5924fe6 Compare June 5, 2022 12:19
@markstos
Copy link
Contributor Author

markstos commented Jun 5, 2022

I've also added a fix to #508 to this PR, as it would have conflicted if I'd submitted it independently.

The Jekyll docs are clear that posts go in "\_posts" (with an
underscore):

https://jekyllrb.com/docs/structure/

While "posts" (no underscore) may be the the name of an output directory
with rendered HTML.

Because HTML is also valid as an impout format, importing "posts" is
no longer supported to avoid confusion.
@markstos
Copy link
Contributor Author

markstos commented Jun 5, 2022

I implemented support for HTML format content (#507) on this branch, since it was also going to conflict badly if I started that work based on main.

@markstos
Copy link
Contributor Author

markstos commented Jun 6, 2022

As I've discovered more importing bugs with easy fixes, this PR can be considered still in progress for now if you don't mind a bigger collection of fixes to review later.

I also found a bug in this PR: I used @tryghost/errors, but I didn't didn't add it to package.json, and I didn't call it correctly. The happy path doesn't trigger that code path. I can fix that as well.

I"m not able to find a reference for the complete list of Markdown
file extensions that Jekyll supports, but instance uses ".markdown"
and I don't seem to have done anything special to enable that.
The location of the drafts folder should be _drafts, not "drafts".

Also, support ".markdown" extension in more spots.
HTML posts are detected using an ".html" file extension.

Before, the entire contents of Jekyll posts was referred to as
"Markdown". This was not completely accurate, as it is a combination of "front
matter" plus Markdown. And this not accurate at all ilf the file content
was actually html. Now, we use "fileContents" to refer to the whole
file.

Before, the front matter was being parsed twice, once during metadata
processing and a second time for "markdown" processing. Now, frontmatter
only gets processed ones, which should be a small speed-up.

Before, "process-content.js" was almost exclusively updating HTML and
not any other type of content. Now that HTML support has been added,
that's the only thing that it does, so it renamed "process-html.js" to
be more clear.

I'm not sure if Jekyll supports multiple extensions for HTML files like
it does for Markdown files. Here only support for ".html" is added. If
an unknown file type is detected, an error will be thrown.

Fixes TryGhost#507
This is for consistency with how `js-yaml` parses the "date"
frontmatter, which will be dealt with in a future commit.

Also, fix the inaccurate comment that was trying to explain JavaScript's
0-based dates, but got confused itself in the process.
Unlike quoted dates, the underlying js-yaml library parses these
directly into date objects.

Fixes TryGhost#511
Linting rules require throwing GhostErrors, which have the web in mind.
The user intended to migrate some blog posts. If no content was found,
report an error instead of reporting "Successfully imported zero posts"
First, the intent was to read files in the `_drafts/` folder was well,
but the Regex was not matching it.

Second, the intent was to match against the path stored in the the
zipfile, but that was broken. Confusingly, "entryName" holds just the
file name while "zipEntry.entryName" holds the full path. The fix is
to switch "entryName" we use.

Third, only the bare file name was being reported when skipped. It's
more useful to see the full path within the zip, in case the problem is
with the folder structure in there.

Fixes TryGhost#510
Before, the first tag would have been imported first as the "primary tag".

Now, because the Ghost's "primary tag" is the best approximation of
Jekyll's "category", we import the "category first".
@markstos
Copy link
Contributor Author

markstos commented Jun 7, 2022

I'm finishing pushing bug fixes to this branch for now.

I'm currently stuck on a bug where scraping is happening even with --scrape=none and I'm not sure how to fix that ( #515 ).

Before, the code /and/ tests wrongly assumed that Jekyl resolved
relative-to-root URLs relative to the blogs "url", but it resolves them
to the origin domain.

Fixes TryGhost#516
@markstos markstos changed the title Jekyll: import _posts, not "posts" Jekyll: Fix many bugs, add new features Jun 8, 2022
@PaulAdamDavis PaulAdamDavis merged commit fa2ff09 into TryGhost:main Jul 9, 2022
@PaulAdamDavis
Copy link
Member

Hey @markstos, thank you so much for your efforts and expertise here, it's massively appreciated! All of this has been merged 🙌

@markstos markstos deleted the rename-posts branch July 13, 2022 17:56
@markstos
Copy link
Contributor Author

@PaulAdamDavis Thanks for the merge and your maintainership!

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