natemoo-re / astro-remote

Render remote HTML or Markdown content in Astro with full control over the output
MIT License
175 stars 9 forks source link

Finding that when using the <Markdown /> component it looks like the internal component is going into a loop or something similar? #38

Open rebron1900 opened 2 weeks ago

rebron1900 commented 2 weeks ago

The build time grows progressively for each page, and the odds are that it's stuck in some kind of dead loop. I've since switched to using the marked library's parse method to build properly.

image

I use JSON data with MD content.

https://memos.1900.live/api/v1/memo?creatorId=101&limit=all

Error page code

---
import { pages, settings, authors, memos } from '../../data/ghost-store.js';
import { marked } from 'marked';
import { Markdown } from 'astro-remote';
import type { GetStaticPathsOptions } from 'astro';

import BaseLayout from '../../layouts/BaseLayout.astro';
import Head from '../../components/Head.astro';
import Relitu from '../../components/Relitu.jsx';
import Header from '../../components/Header.astro';
import Top from '../../components/Top.astro';
import Menu from '../../components/Menu.astro';
import TocTagloop from '../../components/TocTagloop.astro';

const custompage = pages.find((post) => post.slug == 'memos');

export async function getStaticPaths({ paginate }: GetStaticPathsOptions) {
    const db = memos;
    return paginate(db, {
        pageSize: 15
    });
}

const { page } = Astro.props;
---

<BaseLayout post={custompage}>
    <Head slot="head" post={custompage} site={settings} title={custompage?.title + ' | ' + settings?.title + ' - ' + settings?.description} />

    <Header slot="header" title={custompage.title} />
    <Menu slot="menu" />

    <div slot="content" class="markdown book-article page-memos">
        <div class="memo-header" style={`background-image: url(${authors.authors[0].cover_image});`}>
            <div class="memo-info">
                <div class="flex align-center">
                    <span class="memo-title">{authors.authors[0].name}</span>
                    <div class="memo-avartar">
                        <img class="" src={authors.authors[0].profile_image} data-sizes="auto" />
                    </div>
                </div>
                <div class="memo-desc">纵使生活有千般不如意,也不要自暴自弃!</div>
            </div>
        </div>

        <div id="atk-memoslist">
            {
                page.data.map((memo) => (
                    <div class="atk-comment">
                        <div class="atk-avatar">
                            <a target="_blank" rel="noreferrer noopener nofollow" href="#">
                                <img src={authors.authors[0].profile_image} />
                            </a>
                        </div>

                        <div class="atk-main">
                            <div class="atk-body">
                                <div class="atk-content">
                                    <Markdown content={memo.content} />
                                    <div class="resource-wrapper">
                                        <div class="images-wrapper my-2" view-image="">
                                            <template x-for="img in item.resourceList">
                                                <div class="memo-resource w-100">
                                                    <img class="lazyload  medium-zoom-image" data-loaded="true" />
                                                </div>
                                            </template>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                ))
            }
            <div class="flex flex-wrap btn-more justify-center" style="padding: 3rem; gap:1.5rem">
                {
                    page.url.next && (
                        <a
                            class="loader"
                            href="javascript:(void)"
                            hx-trigger="revealed"
                            hx-get={`${page.url.next}`}
                            hx-target="#atk-memoslist"
                            hx-swap="beforeend transition:true "
                            hx-select="#atk-memoslist"
                        />
                    )
                }
            </div>
        </div>

        <script>
            import 'https://unpkg.com/htmx.org@2.0.2';
            import 'artalk/dist/Artalk.css';

            document.addEventListener('astro:page-load', () => {
                document.body.addEventListener('htmx:afterSwap', function (event) {
                    document.querySelector('.btn-more')?.remove();
                });
            });
        </script>
    </div>

    <Relitu slot="relitu" />

    <Fragment slot="toc">
        <Relitu />
        <TocTagloop />
        <Top />
    </Fragment>
</BaseLayout>
twodft commented 2 weeks ago

This seems similar to #33 , and there is a pr #35 intended to fix this