mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 12:17:24 +00:00
fix related resources rendering
This commit is contained in:
@@ -453,7 +453,11 @@ class Network {
|
||||
async getResourceDetails(id: number): Promise<Response<ResourceDetails>> {
|
||||
try {
|
||||
const response = await axios.get(`${this.apiBaseUrl}/resource/${id}`)
|
||||
return response.data
|
||||
let data = response.data
|
||||
if (!data.related) {
|
||||
data.related = []
|
||||
}
|
||||
return data
|
||||
} catch (e: any) {
|
||||
console.error(e)
|
||||
return {
|
||||
|
@@ -229,15 +229,13 @@ function Article({ resource }: { resource: ResourceDetails }) {
|
||||
|
||||
useEffect(() => {
|
||||
if (articleRef.current) {
|
||||
console.log("render")
|
||||
if (!resource.related) {
|
||||
return;
|
||||
}
|
||||
for (let child of articleRef.current.children) {
|
||||
console.log("child", child)
|
||||
if (child.tagName === "P" && child.children.length === 1 && child.children[0].tagName === "A") {
|
||||
const href = (child.children[0] as HTMLAnchorElement).href as string
|
||||
console.log("href", href)
|
||||
console.log("origin", window.location.origin)
|
||||
if (href.startsWith(window.location.origin) || href.startsWith("/")) {
|
||||
console.log("href starts with origin")
|
||||
let path = href
|
||||
if (path.startsWith(window.location.origin)) {
|
||||
path = path.substring(window.location.origin.length)
|
||||
|
Reference in New Issue
Block a user