feat: text version for posts
This commit is contained in:
		
							parent
							
								
									6474fbcac1
								
							
						
					
					
						commit
						e59c84bb2f
					
				
					 1 changed files with 25 additions and 0 deletions
				
			
		
							
								
								
									
										25
									
								
								src/pages/post/[...slug].txt.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								src/pages/post/[...slug].txt.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,25 @@
 | 
			
		|||
import { getCollection } from 'astro:content';
 | 
			
		||||
 | 
			
		||||
export const prerender = true;
 | 
			
		||||
export async function getStaticPaths() {
 | 
			
		||||
    const blogEntries = await getCollection('posts');
 | 
			
		||||
    return blogEntries.map(entry => ({
 | 
			
		||||
        params: { slug: entry.slug }, props: { entry },
 | 
			
		||||
    }));
 | 
			
		||||
}
 | 
			
		||||
export async function GET({ props }) {
 | 
			
		||||
    const { entry } = props;
 | 
			
		||||
    // Format the content as plain text
 | 
			
		||||
    const title = entry.data.title;
 | 
			
		||||
    const date = entry.data.pubDate.toISOString().split('T')[0];
 | 
			
		||||
    const content = entry.body;
 | 
			
		||||
 | 
			
		||||
    // Combine the post info and body into a single text file
 | 
			
		||||
    const textContent = `Title: ${title}\nPublished at: ${date}\n\n${content}`;
 | 
			
		||||
 | 
			
		||||
    return new Response(textContent, {
 | 
			
		||||
        headers: {
 | 
			
		||||
            'Content-Type': 'text/plain',
 | 
			
		||||
        },
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue