feat: under maintenance
This commit is contained in:
parent
d8d5b808b7
commit
d5bf4217a8
3 changed files with 83 additions and 67 deletions
|
@ -6,4 +6,4 @@ export const SITE_AUTHOR_MASTODON = 'https://social.ayco.io/@ayo'
|
||||||
export const SITE_PROJECT_REPO = 'https://github.com/ayoayco/Cozy'
|
export const SITE_PROJECT_REPO = 'https://github.com/ayoayco/Cozy'
|
||||||
export const SITE_DESCRIPTION = 'The Web is Yours.'
|
export const SITE_DESCRIPTION = 'The Web is Yours.'
|
||||||
|
|
||||||
export const VERSION = 'Drooling-Dogs'
|
export const VERSION = 'Exhilirating-Experience'
|
||||||
|
|
|
@ -1,74 +1,16 @@
|
||||||
---
|
---
|
||||||
import { createClient, type RedisJSON } from 'redis'
|
|
||||||
import { type ArticleData, extract } from '@extractus/article-extractor'
|
|
||||||
|
|
||||||
import AddressBar from '../components/AddressBar.astro'
|
|
||||||
import Post from '../components/Post.astro'
|
|
||||||
import App from '../layouts/App.astro'
|
import App from '../layouts/App.astro'
|
||||||
import Library from '../components/Library.astro'
|
import Library from '../components/Library.astro'
|
||||||
import Footer from '../components/Footer.astro'
|
import Footer from '../components/Footer.astro'
|
||||||
|
|
||||||
// Initialize Redis client
|
|
||||||
const client = createClient()
|
|
||||||
client.on('error', (err) => console.error('Redis Client Error', err))
|
|
||||||
await client.connect()
|
|
||||||
|
|
||||||
// Disable prerendering for dynamic content
|
|
||||||
export const prerender = false
|
|
||||||
|
|
||||||
// Get URL parameter from query string
|
|
||||||
let url = Astro.url.searchParams.get('url')
|
|
||||||
let article: ArticleData | null = { url: '/' }
|
|
||||||
|
|
||||||
// Handle redirect loops by extracting URL from nested parameters
|
|
||||||
while (url?.startsWith(Astro.url.origin)) {
|
|
||||||
try {
|
|
||||||
// Parse the URL to extract search parameters
|
|
||||||
const parsedUrl = new URL(url)
|
|
||||||
url = parsedUrl.searchParams.get('url')
|
|
||||||
} catch {
|
|
||||||
// If URL parsing fails, break the loop
|
|
||||||
console.error('Failed to parse URL:', url)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process article extraction only if a valid URL is provided
|
|
||||||
if (url && url !== '/' && url !== '') {
|
|
||||||
const cacheKey = 'cozy:url:' + url
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Check if article exists in Redis cache
|
|
||||||
const exists = await client.exists(cacheKey)
|
|
||||||
|
|
||||||
if (exists) {
|
|
||||||
// Retrieve cached article data
|
|
||||||
article = (await client.json.get(cacheKey)) as ArticleData
|
|
||||||
console.log('>>> Using cached content', article.url)
|
|
||||||
} else {
|
|
||||||
// Fetch article from the web
|
|
||||||
article = await extract(url)
|
|
||||||
console.log('>>> Using fetched content', article?.url)
|
|
||||||
|
|
||||||
if (article !== null && article.url) {
|
|
||||||
// Cache the fetched article in Redis
|
|
||||||
await client.json.set(cacheKey, '$', article as RedisJSON)
|
|
||||||
console.log('>>> Added to cache', article.url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
// Log error and continue with null article
|
|
||||||
console.error('Error processing article:', error)
|
|
||||||
article = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<App article={article}>
|
<App article={null}>
|
||||||
<AddressBar url={url} />
|
<h1>Under Maintenance</h1>
|
||||||
<div slot="post" id="router-outlet">
|
<p>
|
||||||
<Post article={article} />
|
Currently performing scheduled maintenance, working to improve your
|
||||||
</div>
|
experience. Please check back soon. We apologize for any inconvenience this
|
||||||
<Library slot="library" skipSave={article === null} />
|
may cause.
|
||||||
|
</p>
|
||||||
|
<Library slot="library" skipSave={true} />
|
||||||
<Footer slot="footer" />
|
<Footer slot="footer" />
|
||||||
</App>
|
</App>
|
||||||
|
|
74
src/pages/index.astro.bkup
Normal file
74
src/pages/index.astro.bkup
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
---
|
||||||
|
import { createClient, type RedisJSON } from 'redis'
|
||||||
|
import { type ArticleData, extract } from '@extractus/article-extractor'
|
||||||
|
|
||||||
|
import AddressBar from '../components/AddressBar.astro'
|
||||||
|
import Post from '../components/Post.astro'
|
||||||
|
import App from '../layouts/App.astro'
|
||||||
|
import Library from '../components/Library.astro'
|
||||||
|
import Footer from '../components/Footer.astro'
|
||||||
|
|
||||||
|
// Initialize Redis client
|
||||||
|
const client = createClient()
|
||||||
|
client.on('error', (err) => console.error('Redis Client Error', err))
|
||||||
|
await client.connect()
|
||||||
|
|
||||||
|
// Disable prerendering for dynamic content
|
||||||
|
export const prerender = false
|
||||||
|
|
||||||
|
// Get URL parameter from query string
|
||||||
|
let url = Astro.url.searchParams.get('url')
|
||||||
|
let article: ArticleData | null = { url: '/' }
|
||||||
|
|
||||||
|
// Handle redirect loops by extracting URL from nested parameters
|
||||||
|
while (url?.startsWith(Astro.url.origin)) {
|
||||||
|
try {
|
||||||
|
// Parse the URL to extract search parameters
|
||||||
|
const parsedUrl = new URL(url)
|
||||||
|
url = parsedUrl.searchParams.get('url')
|
||||||
|
} catch {
|
||||||
|
// If URL parsing fails, break the loop
|
||||||
|
console.error('Failed to parse URL:', url)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process article extraction only if a valid URL is provided
|
||||||
|
if (url && url !== '/' && url !== '') {
|
||||||
|
const cacheKey = 'cozy:url:' + url
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Check if article exists in Redis cache
|
||||||
|
const exists = await client.exists(cacheKey)
|
||||||
|
|
||||||
|
if (exists) {
|
||||||
|
// Retrieve cached article data
|
||||||
|
article = (await client.json.get(cacheKey)) as ArticleData
|
||||||
|
console.log('>>> Using cached content', article.url)
|
||||||
|
} else {
|
||||||
|
// Fetch article from the web
|
||||||
|
article = await extract(url)
|
||||||
|
console.log('>>> Using fetched content', article?.url)
|
||||||
|
|
||||||
|
if (article !== null && article.url) {
|
||||||
|
// Cache the fetched article in Redis
|
||||||
|
await client.json.set(cacheKey, '$', article as RedisJSON)
|
||||||
|
console.log('>>> Added to cache', article.url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// Log error and continue with null article
|
||||||
|
console.error('Error processing article:', error)
|
||||||
|
article = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
---
|
||||||
|
|
||||||
|
<App article={article}>
|
||||||
|
<AddressBar url={url} />
|
||||||
|
<div slot="post" id="router-outlet">
|
||||||
|
<Post article={article} />
|
||||||
|
</div>
|
||||||
|
<Library slot="library" skipSave={article === null} />
|
||||||
|
<Footer slot="footer" />
|
||||||
|
</App>
|
Loading…
Reference in a new issue