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