11import itemId , { type ItemId } from '$lib/itemId' ;
22import consts from '$lib/consts' ;
3- import { getItemInfo , itemExists } from '$lib/server/data/item' ;
3+ import { getItemData , getItemInfo , itemExists } from '$lib/server/data/item' ;
44import { itemFileUrl } from '$lib/urls' ;
55import { error } from '@sveltejs/kit' ;
66import { create } from 'xmlbuilder2' ;
7- import type { AuthorInfo } from '$lib/server/data/item/item' ;
7+ import type { ItemData } from '$lib/server/data/item/item' ;
88import { dev , version } from '$app/environment' ;
99import { getConfig } from '$lib/server/data/config' ;
1010import type { XMLBuilder } from 'xmlbuilder2/lib/interfaces' ;
1111import { unixTime , unixToIsoTime } from '$lib/util' ;
12+ import { getItemAuthor } from '$lib/itemData' ;
1213
1314type Request = import ( './$types' ) . RequestEvent ;
1415
@@ -40,6 +41,8 @@ export async function GET(req: Request) {
4041 error ( 404 , `Item ${ item } does not have an Atom feed` ) ;
4142 }
4243
44+ const portfolio = await getItemData ( itemId . ROOT ) ;
45+
4346 const baseUrl = `${ req . url . protocol } //${ req . url . host } ` ;
4447 const itemUrl = `${ baseUrl } ${ item === '/' ? '' : item } ` ;
4548
@@ -65,7 +68,7 @@ export async function GET(req: Request) {
6568 // Add basic info
6669 root . ele ( 'title' ) . txt ( info . feed . title ) ;
6770 root . ele ( 'id' ) . txt ( itemUrl ) ;
68- await addAuthorInfo ( item , root ) ;
71+ addAuthorInfo ( item , root , portfolio ) ;
6972
7073 // Feed subtitle -- use SEO description if possible
7174 root . ele ( 'subtitle' ) . txt ( info . seo . description ?? info . description ) ;
@@ -117,8 +120,7 @@ export async function GET(req: Request) {
117120 xmlChild . ele ( 'summary' ) . txt ( childInfo . seo . description ?? childInfo . description ) ;
118121
119122 // Author info
120- // eslint-disable-next-line no-await-in-loop
121- await addAuthorInfo ( childId , xmlChild ) ;
123+ addAuthorInfo ( childId , xmlChild , portfolio ) ;
122124
123125 // Content: link to site
124126 // xmlChild.ele('content').att('src', childUrl).att('type', consts.MIME_TYPES.HTML);
@@ -145,8 +147,8 @@ export async function GET(req: Request) {
145147 ) ;
146148}
147149
148- async function addAuthorInfo ( item : ItemId , node : XMLBuilder ) {
149- const authorInfo = await getFeedAuthor ( item ) ;
150+ function addAuthorInfo ( item : ItemId , node : XMLBuilder , portfolio : ItemData ) {
151+ const authorInfo = getItemAuthor ( item , portfolio ) ;
150152 if ( authorInfo ) {
151153 const xmlAuthor = node . ele ( 'author' ) ;
152154 if ( authorInfo . name ) {
@@ -160,16 +162,3 @@ async function addAuthorInfo(item: ItemId, node: XMLBuilder) {
160162 }
161163 }
162164}
163-
164- async function getFeedAuthor ( item : ItemId ) : Promise < AuthorInfo | null > {
165- for ( const ancestor of itemId . ancestors ( item ) ) {
166- // Really should look this info up in parallel
167- // At least it'll be better once I cache the data again...
168- // eslint-disable-next-line no-await-in-loop
169- const info = await getItemInfo ( ancestor ) ;
170- if ( info . author ) {
171- return info . author ;
172- }
173- }
174- return null ;
175- }
0 commit comments