question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Creating an index page for all posts

See original GitHub issue

I’d like to have the blog/ page broken up to where I have

  • https://my-site.com/blog/ is containing all of the created posts

  • https://my-site.com/blog/this-is-a-post is a specific post.

I know I can pass a different template to blog/route.js

module.exports = {
  template: 'BlogPost.svelte',
  permalink: ({ request }) => `blog/${request.slug}/`,
  all: () => [],
  data: {},
};

…but how do I create a singular index page? Simply have a Blog.svelte file for the default route?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
nickreesecommented, Nov 1, 2020

I think I follow the issue. Here is how you would specify different templates in the route.js and you can do something similar based on some field in frontmatter of the individual post from within BlogPost.svelte.

Route.js:

module.exports = {
  template: 'Blog.svelte',
  permalink: ({ request, settings }) => `/${request.blog.slug}/${request.slug}/`,
  all: async () => {
    return [{ blog: { slug: 'blog' }, template: 'BlogIndex' }];
  },

  data: ({ data }) => {
    return data;
  },
};

Blog.svelte

<script>
  import BlogIndex from './BlogIndex.svelte';
  import BlogPost from './BlogPost.svelte';

  export let settings, data, helpers, request;

  let component = BlogPost;

  if (request.template === 'BlogIndex') {
    component = BlogIndex;
  } 
</script>

<svelte:component this={component} {settings} {data} {helpers} {request} />
0reactions
ViorelMocanucommented, Sep 12, 2021

I have the exact same issue and I’ve tried the latter method to no avail. The blog posts load correctly after having been passed through the Blog.svelte equivalent, but the index just throws a Not Found on me incessantly.

My blog folder is informatii-utile (which has all the .md files inside), my routing proxy is InformatiiUtile.svelte and the two templates are BlogIndex.svelte and BlogPosts.svelte. Exact structure is shown here.

I will be reproducing the relevant files here in hopes that someone might help:

route.js

module.exports = {
  template: 'InformatiiUtile.svelte',
  data: ({ data }) => {
    return data;
  },
  all: async () => {
    return [
      {
        'informatii-utile': { slug: 'informatii-utile', template: 'BlogIndex' },
        template: 'BlogIndex',
      },
    ];
  },
  permalink: '/informatii-utile/:slug/',
};

InformatiiUtile.svelte

<script>
  import BlogIndex from './BlogIndex.svelte';
  import BlogPost from './BlogPost.svelte';
  export let data, helpers, request, settings;
  const { html, frontmatter } = data;

  let component = BlogPost;
  if (request.template === 'BlogIndex') {
    component = BlogIndex;
  }
</script>

<svelte:component this={component} {settings} {data} {helpers} {request} />

Thank you in advance!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create the blog posts index page in WordPress
Blog Posts Index page as Internal Page ; Step 1) Create a page called “Blog” or “Articles” or “Name it what-ever-you-want”. ; step...
Read more >
creating an index page of posts - WordPress.org
So — how do I create an index page for all the Posts in this Category? Ideally I'd like to display the post...
Read more >
Creating an Index on WordPress.com | The Daily Post
Sometimes, though, you might want to create a more specific index of your contents than category pages or monthly archives allow.
Read more >
Creating an index for recipes or other content
A recipe or content index is a great way to organize your blog posts so visitors can quickly browse your content. Create a...
Read more >
WordPress Index Plugin: Create an Index of Your Website ...
Create an index of WordPress pages, blog posts, or any custom post type (e.g. e-commerce products, events, documents, portfolio case studies ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found