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

Deprecate drafts feature #8099

Merged
merged 7 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/silent-bikes-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@astrojs/rss': patch
'astro': patch
---

Deprecate the `markdown.drafts` configuration option.

If you'd like to create draft pages that are visible in dev but not in production, you can [migrate to content collections](https://docs.astro.build/en/guides/content-collections/#migrating-from-file-based-routing) and [manually filter out pages](https://docs.astro.build/en/guides/content-collections/#filtering-collection-queries) with the `draft: true` frontmatter property instead.
4 changes: 2 additions & 2 deletions packages/astro-rss/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ export function get(context) {
site: context.site,
// list of `<item>`s in output xml
items: [...],
// include draft posts in the feed (default: false)
drafts: true,
// (optional) absolute path to XSL stylesheet in your project
stylesheet: '/rss-styles.xsl',
// (optional) inject custom xml
Expand Down Expand Up @@ -118,6 +116,8 @@ When providing a formatted RSS item list, see the [`RSSFeedItem` type reference]

Type: `boolean (optional)`

**Deprecated**: Manually filter `items` instead.

Set `drafts: true` to include [draft posts](https://docs.astro.build/en/guides/markdown-content/#draft-pages) in the feed output. By default, this option is `false` and draft posts are not included.

### stylesheet
Expand Down
10 changes: 8 additions & 2 deletions packages/astro-rss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ export type RSSOptions = {
stylesheet?: z.infer<typeof rssOptionsValidator>['stylesheet'];
/** Specify custom data in opening of file */
customData?: z.infer<typeof rssOptionsValidator>['customData'];
/** Whether to include drafts or not */
/**
* Whether to include drafts or not
* @deprecated Deprecated since version 3.0. Use content collections instead.
*/
drafts?: z.infer<typeof rssOptionsValidator>['drafts'];
trailingSlash?: z.infer<typeof rssOptionsValidator>['trailingSlash'];
};
Expand All @@ -45,7 +48,10 @@ export type RSSFeedItem = {
description?: z.infer<typeof rssSchema>['description'];
/** Append some other XML-valid data to this item */
customData?: z.infer<typeof rssSchema>['customData'];
/** Whether draft or not */
/**
* Whether draft or not
* @deprecated Deprecated since version 3.0. Use content collections instead.
*/
draft?: z.infer<typeof rssSchema>['draft'];
/** Categories or tags related to the item */
categories?: z.infer<typeof rssSchema>['categories'];
Expand Down
9 changes: 7 additions & 2 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ export interface AstroUserConfig {
* @name build.split
* @type {boolean}
* @default `false`
* @deprecated since version 3.0
* @deprecated Deprecated since version 3.0.
* @description
* The build config option `build.split` has been replaced by the adapter configuration option [`functionPerRoute`](/en/reference/adapter-reference/#functionperroute).
*
Expand All @@ -870,7 +870,7 @@ export interface AstroUserConfig {
* @name build.excludeMiddleware
* @type {boolean}
* @default `false`
* @deprecated since version 3.0
* @deprecated Deprecated since version 3.0.
* @description
* The build config option `build.excludeMiddleware` has been replaced by the adapter configuration option [`edgeMiddleware`](/en/reference/adapter-reference/#edgemiddleware).
*
Expand Down Expand Up @@ -1064,6 +1064,7 @@ export interface AstroUserConfig {
* @name markdown.drafts
* @type {boolean}
* @default `false`
* @deprecated Deprecated since version 3.0. Use content collections instead.
* @description
* Control whether Markdown draft pages should be included in the build.
*
Expand Down Expand Up @@ -1510,6 +1511,10 @@ export interface ComponentInstance {
default: AstroComponentFactory;
css?: string[];
prerender?: boolean;
/**
* Only used for logging if deprecated drafts feature is used
*/
frontmatter?: Record<string, any>;
getStaticPaths?: (options: GetStaticPathsOptions) => GetStaticPathsResult;
}

Expand Down
5 changes: 5 additions & 0 deletions packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ async function generatePage(
const pageModule = await pageModulePromise();
if (shouldSkipDraft(pageModule, pipeline.getSettings())) {
logger.info(null, `${magenta('⚠️')} Skipping draft ${pageData.route.component}`);
// TODO: Remove in Astro 4.0
logger.warn(
'astro',
`The drafts feature is deprecated. You should migrate to content collections instead. See https://docs.astro.build/en/guides/content-collections/#filtering-collection-queries for more information.`
);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/errors/errors-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const UnknownCompilerError = {
* The `Astro.redirect` function is only available when [Server-side rendering](/en/guides/server-side-rendering/) is enabled.
*
* To redirect on a static website, the [meta refresh attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta) can be used. Certain hosts also provide config-based redirects (ex: [Netlify redirects](https://docs.netlify.com/routing/redirects/)).
* @deprecated since version 2.6
* @deprecated Deprecated since version 2.6.
*/
export const StaticRedirectNotAvailable = {
name: 'StaticRedirectNotAvailable',
Expand Down
10 changes: 10 additions & 0 deletions packages/astro/src/core/render/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
import { renderPage as runtimeRenderPage } from '../../runtime/server/index.js';
import { attachCookiesToResponse } from '../cookies/index.js';
import { callEndpoint, createAPIContext } from '../endpoint/index.js';
import { warn } from '../logger/core.js';
import { callMiddleware } from '../middleware/callMiddleware.js';
import { redirectRouteGenerate, redirectRouteStatus, routeIsRedirect } from '../redirects/index.js';
import type { RenderContext } from './context.js';
Expand Down Expand Up @@ -57,6 +58,15 @@ export async function renderPage({ mod, renderContext, env, cookies }: RenderPag
locals: renderContext.locals ?? {},
});

// TODO: Remove in Astro 4.0
if (mod.frontmatter && typeof mod.frontmatter === 'object' && 'draft' in mod.frontmatter) {
warn(
env.logging,
'astro',
`The drafts feature is deprecated and used in ${renderContext.route.component}. You should migrate to content collections instead. See https://docs.astro.build/en/guides/content-collections/#filtering-collection-queries for more information.`
);
}

const response = await runtimeRenderPage(
result,
Component,
Expand Down