Skip to content

Commit 732111c

Browse files
bluwysarah11918
andauthored
Deprecate drafts feature (#8099)
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
1 parent f003e73 commit 732111c

7 files changed

Lines changed: 41 additions & 7 deletions

File tree

.changeset/silent-bikes-crash.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@astrojs/rss': patch
3+
'astro': patch
4+
---
5+
6+
Deprecate the `markdown.drafts` configuration option.
7+
8+
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.

packages/astro-rss/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ export function get(context) {
6565
site: context.site,
6666
// list of `<item>`s in output xml
6767
items: [...],
68-
// include draft posts in the feed (default: false)
69-
drafts: true,
7068
// (optional) absolute path to XSL stylesheet in your project
7169
stylesheet: '/rss-styles.xsl',
7270
// (optional) inject custom xml
@@ -118,6 +116,8 @@ When providing a formatted RSS item list, see the [`RSSFeedItem` type reference]
118116

119117
Type: `boolean (optional)`
120118

119+
**Deprecated**: Manually filter `items` instead.
120+
121121
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.
122122

123123
### stylesheet

packages/astro-rss/src/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ export type RSSOptions = {
2727
stylesheet?: z.infer<typeof rssOptionsValidator>['stylesheet'];
2828
/** Specify custom data in opening of file */
2929
customData?: z.infer<typeof rssOptionsValidator>['customData'];
30-
/** Whether to include drafts or not */
30+
/**
31+
* Whether to include drafts or not
32+
* @deprecated Deprecated since version 3.0. Use content collections instead.
33+
*/
3134
drafts?: z.infer<typeof rssOptionsValidator>['drafts'];
3235
trailingSlash?: z.infer<typeof rssOptionsValidator>['trailingSlash'];
3336
};
@@ -45,7 +48,10 @@ export type RSSFeedItem = {
4548
description?: z.infer<typeof rssSchema>['description'];
4649
/** Append some other XML-valid data to this item */
4750
customData?: z.infer<typeof rssSchema>['customData'];
48-
/** Whether draft or not */
51+
/**
52+
* Whether draft or not
53+
* @deprecated Deprecated since version 3.0. Use content collections instead.
54+
*/
4955
draft?: z.infer<typeof rssSchema>['draft'];
5056
/** Categories or tags related to the item */
5157
categories?: z.infer<typeof rssSchema>['categories'];

packages/astro/src/@types/astro.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ export interface AstroUserConfig {
856856
* @name build.split
857857
* @type {boolean}
858858
* @default `false`
859-
* @deprecated since version 3.0
859+
* @deprecated Deprecated since version 3.0.
860860
* @description
861861
* The build config option `build.split` has been replaced by the adapter configuration option [`functionPerRoute`](/en/reference/adapter-reference/#functionperroute).
862862
*
@@ -870,7 +870,7 @@ export interface AstroUserConfig {
870870
* @name build.excludeMiddleware
871871
* @type {boolean}
872872
* @default `false`
873-
* @deprecated since version 3.0
873+
* @deprecated Deprecated since version 3.0.
874874
* @description
875875
* The build config option `build.excludeMiddleware` has been replaced by the adapter configuration option [`edgeMiddleware`](/en/reference/adapter-reference/#edgemiddleware).
876876
*
@@ -1064,6 +1064,7 @@ export interface AstroUserConfig {
10641064
* @name markdown.drafts
10651065
* @type {boolean}
10661066
* @default `false`
1067+
* @deprecated Deprecated since version 3.0. Use content collections instead.
10671068
* @description
10681069
* Control whether Markdown draft pages should be included in the build.
10691070
*
@@ -1510,6 +1511,10 @@ export interface ComponentInstance {
15101511
default: AstroComponentFactory;
15111512
css?: string[];
15121513
prerender?: boolean;
1514+
/**
1515+
* Only used for logging if deprecated drafts feature is used
1516+
*/
1517+
frontmatter?: Record<string, any>;
15131518
getStaticPaths?: (options: GetStaticPathsOptions) => GetStaticPathsResult;
15141519
}
15151520

packages/astro/src/core/build/generate.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ async function generatePage(
261261
const pageModule = await pageModulePromise();
262262
if (shouldSkipDraft(pageModule, pipeline.getSettings())) {
263263
logger.info(null, `${magenta('⚠️')} Skipping draft ${pageData.route.component}`);
264+
// TODO: Remove in Astro 4.0
265+
logger.warn(
266+
'astro',
267+
`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.`
268+
);
264269
return;
265270
}
266271

packages/astro/src/core/errors/errors-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const UnknownCompilerError = {
4242
* The `Astro.redirect` function is only available when [Server-side rendering](/en/guides/server-side-rendering/) is enabled.
4343
*
4444
* 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/)).
45-
* @deprecated since version 2.6
45+
* @deprecated Deprecated since version 2.6.
4646
*/
4747
export const StaticRedirectNotAvailable = {
4848
name: 'StaticRedirectNotAvailable',

packages/astro/src/core/render/core.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
import { renderPage as runtimeRenderPage } from '../../runtime/server/index.js';
99
import { attachCookiesToResponse } from '../cookies/index.js';
1010
import { callEndpoint, createAPIContext } from '../endpoint/index.js';
11+
import { warn } from '../logger/core.js';
1112
import { callMiddleware } from '../middleware/callMiddleware.js';
1213
import { redirectRouteGenerate, redirectRouteStatus, routeIsRedirect } from '../redirects/index.js';
1314
import type { RenderContext } from './context.js';
@@ -57,6 +58,15 @@ export async function renderPage({ mod, renderContext, env, cookies }: RenderPag
5758
locals: renderContext.locals ?? {},
5859
});
5960

61+
// TODO: Remove in Astro 4.0
62+
if (mod.frontmatter && typeof mod.frontmatter === 'object' && 'draft' in mod.frontmatter) {
63+
warn(
64+
env.logging,
65+
'astro',
66+
`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.`
67+
);
68+
}
69+
6070
const response = await runtimeRenderPage(
6171
result,
6272
Component,

0 commit comments

Comments
 (0)