Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
astro-wt
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
458e87da
authored
2025-02-26 14:27:20 -0600
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Add fetchUrl/externalUrl settings for configured sites.
1 parent
519df665
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
5 deletions
lib/remote-content.ts
lib/remote-content.ts
View file @
458e87d
...
...
@@ -7,6 +7,8 @@ import { parseHtml } from './html.ts'
interface
SiteConfig
{
name
:
string
,
baseUrl
:
string
,
fetchUrl
:
string
,
externalUrl
:
string
,
}
export
const
configSlice
=
createSlice
({
...
...
@@ -15,14 +17,25 @@ export const configSlice = createSlice({
sites
:
{},
},
reducers
:
{
setSiteConfig
(
state
,
{
payload
:
{
name
,
baseUrl
}
})
{
setSiteConfig
(
state
,
{
payload
:
{
name
,
baseUrl
,
fetchUrl
,
externalUrl
}
})
{
if
(
!
state
.
sites
[
name
])
state
.
sites
[
name
]
=
{}
Object
.
assign
(
state
.
sites
[
name
],
{
baseUrl
})
Object
.
assign
(
state
.
sites
[
name
],
{
baseUrl
,
fetchUrl
,
externalUrl
})
}
},
selectors
:
{
getSites
:
(
state
)
=>
Object
.
keys
(
state
.
sites
).
filter
(
site
=>
site
!==
'default'
),
getSiteBaseUrl
:
(
state
,
name
)
=>
state
.
sites
?.[
name
]?.
baseUrl
,
getSiteBaseUrl
:
(
state
,
name
)
=>
{
const
{
sites
:
{
[
name
]:
siteConfig
=
{}
}
=
{}
}
=
state
return
siteConfig
.
baseUrl
},
getSiteFetchUrl
:
(
state
,
name
)
=>
{
const
{
sites
:
{
[
name
]:
siteConfig
=
{}
}
=
{}
}
=
state
return
siteConfig
.
fetchUrl
||
siteConfig
.
baseUrl
},
getSiteExternalUrl
:
(
state
,
name
)
=>
{
const
{
sites
:
{
[
name
]:
siteConfig
=
{}
}
=
{}
}
=
state
return
siteConfig
.
externalUrl
||
siteConfig
.
baseUrl
},
},
})
...
...
@@ -31,8 +44,8 @@ const baseQuery = fetchBaseQuery()
const
siteBaseQuery
=
async
(
args
,
api
,
options
)
=>
{
const
{
site
,
url
}
=
args
const
baseUrl
=
getSiteBase
Url
(
site
)
||
''
return
baseQuery
({
...
args
,
url
:
`
${
base
Url
}${
url
}
`
},
api
,
options
)
const
fetchUrl
=
getSiteFetch
Url
(
site
)
||
''
return
baseQuery
({
...
args
,
url
:
`
${
fetch
Url
}${
url
}
`
},
api
,
options
)
}
export
const
sitePageSlice
=
createApi
({
...
...
@@ -99,6 +112,14 @@ export const getSiteBaseUrl = (name: string): string => {
return
configSlice
.
selectors
.
getSiteBaseUrl
(
store
.
getState
(),
name
)
}
export
const
getSiteFetchUrl
=
(
name
:
string
):
string
=>
{
return
configSlice
.
selectors
.
getSiteFetchUrl
(
store
.
getState
(),
name
)
}
export
const
getSiteExternalUrl
=
(
name
:
string
):
string
=>
{
return
configSlice
.
selectors
.
getSiteExternalUrl
(
store
.
getState
(),
name
)
}
export
const
clearAll
=
()
=>
{
return
store
.
dispatch
(
sitePageSlice
.
util
.
invalidateTags
([
'Page'
]))
}
...
...
Please
register
or
sign in
to post a comment