Skip to content

Add option to control automatic doctype prepend#6084

Closed
Sertion wants to merge 4 commits intowithastro:mainfrom
Sertion:prepend-doctype-option
Closed

Add option to control automatic doctype prepend#6084
Sertion wants to merge 4 commits intowithastro:mainfrom
Sertion:prepend-doctype-option

Conversation

@Sertion
Copy link
Copy Markdown

@Sertion Sertion commented Feb 1, 2023

Changes

Adds a setting to control the automatic doctype prepender as discussed here.

Testing

Added a new test to the doctype tests that verifies that no doctype is added.

Docs

The current proposed implementation adds a new option (prependDoctype type boolean) to the build (?) configuration.

/cc @withastro/maintainers-docs for feedback!

@Sertion Sertion requested a review from a team as a code owner February 1, 2023 14:12
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 1, 2023

🦋 Changeset detected

Latest commit: cd2350b

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Feb 1, 2023
Copy link
Copy Markdown
Member

@yanthomasdev yanthomasdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @Sertion! I added a small docs suggestion for you 🙌

@matthewp
Copy link
Copy Markdown
Contributor

matthewp commented Feb 1, 2023

trying to understand the use-case better. You want to omit the doctype so you can use Astro pages as partials; does this mean that you also omit the head and body tags? I guess that works since we don't automatically append those.

@Sertion
Copy link
Copy Markdown
Author

Sertion commented Feb 2, 2023

You want to omit the doctype so you can use Astro pages as partials; does this mean that you also omit the head and body tags?

That is right. I want to be able to generate HTML output that only contains what I made it to contain without any unexpected side effects. More reasons for other can be found in this discussion.

The use case is rendering content for technology such as the nginx SSI module.

@natemoo-re
Copy link
Copy Markdown
Member

We would like to expose this feature, but I think it's unfortunately going to take more than this. Currently our compiler doesn't preserve doctype statements because we expect the rendering logic to add it for us, so enabling this setting would currently break even if a doctype is added manually in your markup.

@Sertion
Copy link
Copy Markdown
Author

Sertion commented Feb 8, 2023

Thanks for the update @natemoo-re. I looked at @astrojs/compiler to see if I could make the change but I could not.

What would be the next step?

@matthewp
Copy link
Copy Markdown
Contributor

matthewp commented Feb 8, 2023

I think I'm going to have to come out against this feature. Astro doesn't at present support partial generation. Any hacks we add are going to make everything more brittle and confusing for users.

It's called the pages/ folder and expects to generate full pages. Partials are something we could support, I have heard some interest from people on the team, so it's not out of the realm of possibility. But it needs to go through the proposal process and be it's own feature if we are going to do it (which probably, imo, means not going through the pages folder). https://github.com/withastro/roadmap/discussions

Copy link
Copy Markdown
Contributor

@matthewp matthewp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more complicated than a simple change and should go through the roadmap process. https://github.com/withastro/roadmap/discussions

@Sertion
Copy link
Copy Markdown
Author

Sertion commented Feb 8, 2023

This is more complicated than a simple change and should go through the roadmap process. https://github.com/withastro/roadmap/discussions

Should it continue in the existing proposal or would creating a new proposal be preferred?

@natemoo-re
Copy link
Copy Markdown
Member

Thanks for being flexible @Sertion! I think we can continue the discussion in withastro/roadmap#266 and hopefully come up with a more fleshed out proposal from there.

@natemoo-re natemoo-re closed this Feb 9, 2023
@Sertion Sertion deleted the prepend-doctype-option branch February 10, 2023 13:43
@pke
Copy link
Copy Markdown

pke commented May 4, 2023

This would have been helpful to generate humans.txt file dynamically (inserting the updated date into).
Setting the response header works from humans.txt.astro but it will still emit the doctype header :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants