@anthusai/papyrus 5.115.3 → 5.115.4-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/app/page.tsx CHANGED
@@ -2,7 +2,7 @@ import { getSiteRenderer } from "../lib/site-renderer";
2
2
  import { contentRepository, getScenarioIdParam } from "../lib/content-repository";
3
3
  import type { EditionContent } from "../lib/content-types";
4
4
  import { createEditionSectionPlan } from "../lib/edition-sections";
5
- import { getCachedLatestPublishedEdition, loadCachedEditionContent } from "../lib/cached-content-repository";
5
+ import { getCachedLatestPublishedEdition, listCachedNewestArticles, loadCachedEditionContent } from "../lib/cached-content-repository";
6
6
  import { getEditionDatePath } from "../lib/edition-routes";
7
7
  import {
8
8
  EMPTY_EDITION_PLACEHOLDER_SLUG,
@@ -17,8 +17,7 @@ import {
17
17
  import type { PublicationItem } from "../lib/publication-items";
18
18
  import { SITE_BRAND, editionsEnabled, rootRoute } from "../lib/site-brand";
19
19
  import { ItemStreamView } from "../components/item-stream-view";
20
- import { ITEM_STREAM_RECENT_EDITION_COUNT, buildItemStream, selectNewestStreamItems } from "../lib/item-stream";
21
- import { listCachedPublishedEditions } from "../lib/cached-content-repository";
20
+ import { ITEM_STREAM_ITEM_LIMIT, articlesToStreamItems, buildItemStream } from "../lib/item-stream";
22
21
  import { notFound, redirect } from "next/navigation";
23
22
  import { getReaderBasePath } from "../lib/reader-base-path";
24
23
  import { buildRootRedirectTarget } from "../lib/root-route-redirect";
@@ -108,13 +107,10 @@ async function loadNewestStreamItemsOrNone() {
108
107
  }
109
108
  }
110
109
 
110
+ // With editions off the home page is the newest published articles, read straight from the item index.
111
+ // No edition has to exist for an article to be listed.
111
112
  async function loadNewestStreamItems() {
112
- const { editions } = await listCachedPublishedEditions({ limit: ITEM_STREAM_RECENT_EDITION_COUNT });
113
- const newestFirst = [...editions].sort((left, right) => right.editionDate.localeCompare(left.editionDate));
114
- const contents = await Promise.all(
115
- newestFirst.map((edition) => loadCachedEditionContent({ editionDate: edition.editionDate })),
116
- );
117
- return selectNewestStreamItems(contents);
113
+ return articlesToStreamItems(await listCachedNewestArticles(ITEM_STREAM_ITEM_LIMIT));
118
114
  }
119
115
 
120
116
  async function loadLatestGraphQLEdition(): Promise<EditionContent | null> {
@@ -90,6 +90,15 @@ export function getCachedLatestPublishedEdition(): Promise<EditionRouteSummary |
90
90
  );
91
91
  }
92
92
 
93
+ export function listCachedNewestArticles(limit: number): Promise<Article[]> {
94
+ if (bypassReaderCacheInDevelopment) return Promise.resolve(graphqlContentRepository.listNewestArticles(limit));
95
+ return withReaderCache(
96
+ ["reader-newest-articles", String(limit)],
97
+ [ARTICLES_CACHE_TAG, EDITIONS_CACHE_TAG],
98
+ async () => graphqlContentRepository.listNewestArticles(limit),
99
+ );
100
+ }
101
+
93
102
  export function getCachedVideoScript(targetSlug: string): Promise<VideoScriptRef | null> {
94
103
  if (bypassReaderCacheInDevelopment) {
95
104
  return Promise.resolve(graphqlContentRepository.loadVideoScript(targetSlug)).then((result) => result ?? null);
@@ -31,6 +31,9 @@ export const contentRepository: ContentRepository = {
31
31
  listArticleSlugs() {
32
32
  return graphqlContentRepository.listArticleSlugs();
33
33
  },
34
+ listNewestArticles(limit: number) {
35
+ return graphqlContentRepository.listNewestArticles(limit);
36
+ },
34
37
  loadVideoScript(targetSlug: string) {
35
38
  return graphqlContentRepository.loadVideoScript(targetSlug);
36
39
  },
@@ -104,5 +104,7 @@ export type ContentRepository = {
104
104
  getEditionArticle(options: GetEditionArticleOptions): Article | undefined | Promise<Article | undefined>;
105
105
  getEditionItem(options: GetEditionItemOptions): PublicationItem | undefined | Promise<PublicationItem | undefined>;
106
106
  listArticleSlugs(): string[] | Promise<string[]>;
107
+ /** The newest published articles, newest first, read from the item index (no edition needed). */
108
+ listNewestArticles(limit: number): Article[] | Promise<Article[]>;
107
109
  loadVideoScript(targetSlug: string): VideoScriptRef | null | Promise<VideoScriptRef | null>;
108
110
  };
@@ -248,6 +248,14 @@ export const graphqlContentRepository: ContentRepository = {
248
248
  .sort();
249
249
  });
250
250
  },
251
+
252
+ listNewestArticles(limit) {
253
+ return withReaderGraphQLContext(async () => {
254
+ const items = await listNewestItemsByTypeStatus(`${ARTICLE_TYPE}#${PUBLISHED_STATUS}`, limit);
255
+ const visible = items.filter((item) => item.type === ARTICLE_TYPE && isVisibleItemStatus(item.status));
256
+ return Promise.all(visible.map(async (item) => normalizeArticle(item, await listMediaAssets(item.id))));
257
+ });
258
+ },
251
259
  };
252
260
 
253
261
  function getClient(): DataClient {
@@ -712,6 +720,16 @@ async function listItemsByTypeStatus(typeStatus: string): Promise<GraphQLItem[]>
712
720
  );
713
721
  }
714
722
 
723
+ /** One page of the newest published items, read from the typeStatus-by-publishedAt index (never the whole table). */
724
+ async function listNewestItemsByTypeStatus(typeStatus: string, limit: number): Promise<GraphQLItem[]> {
725
+ const response = await getPublishedItemModel().listPublishedItemsByTypeStatusAndPublishedAt(
726
+ { typeStatus },
727
+ { authMode: authMode(), limit: Math.max(1, Math.floor(limit)), sortDirection: "DESC" },
728
+ );
729
+ assertNoGraphQLErrors(response.errors);
730
+ return (response.data ?? []).filter(Boolean) as GraphQLItem[];
731
+ }
732
+
715
733
  async function getItemById(id: string): Promise<GraphQLItem | null> {
716
734
  const response = await getPublishedItemModel().get({ id }, { authMode: authMode() });
717
735
  return readGetResponse<GraphQLItem>(response);
@@ -1,8 +1,8 @@
1
- import type { EditionContent, EditionSection } from "./content-types";
1
+ import type { Article } from "./articles";
2
+ import type { EditionSection } from "./content-types";
2
3
  import { createEditionSectionPlan, createSectionKey } from "./edition-sections";
3
- import { getArticlePublicationItems, type ArticlePublicationItem } from "./publication-items";
4
+ import { articleToPublicationItem, type ArticlePublicationItem } from "./publication-items";
4
5
 
5
- export const ITEM_STREAM_RECENT_EDITION_COUNT = 10;
6
6
  export const ITEM_STREAM_ITEM_LIMIT = 50;
7
7
 
8
8
  export type ItemStream = {
@@ -12,22 +12,17 @@ export type ItemStream = {
12
12
  };
13
13
 
14
14
  /**
15
- * Flattens published content into one newest-first stream of articles. The
16
- * input is ordered newest first; a slug that appears twice keeps its newest entry.
15
+ * The stream's items from the newest published articles, newest first (the order the item index returns them).
16
+ * A slug that appears twice keeps its newest entry.
17
17
  */
18
- export function selectNewestStreamItems(
19
- newestFirstContents: EditionContent[],
20
- limit: number = ITEM_STREAM_ITEM_LIMIT,
21
- ): ArticlePublicationItem[] {
18
+ export function articlesToStreamItems(newestFirstArticles: Article[], limit: number = ITEM_STREAM_ITEM_LIMIT): ArticlePublicationItem[] {
22
19
  const seenSlugs = new Set<string>();
23
20
  const selected: ArticlePublicationItem[] = [];
24
- for (const content of newestFirstContents) {
25
- for (const item of getArticlePublicationItems(content.items)) {
26
- if (seenSlugs.has(item.slug)) continue;
27
- seenSlugs.add(item.slug);
28
- selected.push(item);
29
- if (selected.length >= limit) return selected;
30
- }
21
+ for (const article of newestFirstArticles) {
22
+ if (seenSlugs.has(article.slug)) continue;
23
+ seenSlugs.add(article.slug);
24
+ selected.push(articleToPublicationItem(article));
25
+ if (selected.length >= limit) break;
31
26
  }
32
27
  return selected;
33
28
  }
package/package.json CHANGED
@@ -640,7 +640,7 @@
640
640
  "optional": true
641
641
  }
642
642
  },
643
- "version": "5.115.3",
643
+ "version": "5.115.4-next.1",
644
644
  "dependencies": {
645
645
  "@aws-amplify/adapter-nextjs": "^1.7.3",
646
646
  "@aws-crypto/sha256-js": "5.2.0",
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.115.3",
2
+ "version": "5.115.4-next.1",
3
3
  "routes": [
4
4
  {
5
5
  "file": "app/%5F_preview/[[...path]]/route.ts",