#Keystatic

26 messages · Page 1 of 1 (latest)

stuck panther
#

Im using keystatic as my cms. When I create a table on the body the body is of extensoin of markdown. On my page when i render the body it shows up like this.

{% table %}

Date
Course Name
Course Code
Discipline Name
03/05/24
Name test
ge-104
BS-iT
{% /table %}

Instead of a table?

tropic etherBOT
#

Hi @stuck panther. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

It seems like you're trying to render a table in Markdown format using Keystatic as your CMS. However, the syntax you're using doesn't seem to be standard Markdown syntax for tables.

In Markdown, tables are created using pipes and hyphens. Here's an example:

| Date      | Course Name | Course Code | Discipline Name |
|-----------|-------------|-------------|-----------------|
| 03/05/24  | Name test   | ge-104      | BS-iT           |

This will render as a table in Markdown.

If you're using Astro to render your Markdown content, it supports GitHub Flavored Markdown, which includes table syntax. You can check out the Markdown Guide's Cheat Sheet (https://www.markdownguide.org/cheat-sheet/) for a quick overview of all the Markdown syntax elements, including tables.

If you're still having issues, it might be due to how your content is being rendered in Astro. You can use Astro's Content Collections API to query and display your posts and collections. Here's an example of how to display content from an individual post:

---import { getEntry } from 'astro:content'
const post = await getEntry('posts', 'my-first-post')const { Content } = await post.render()---
<main>  <h1>{post.data.title}</h1>  <Content /></main>

For more information on querying, filtering, displaying your collections content and more, see the full content collections documentation (https://docs.astro.build/en/guides/content-collections/).

#

@stuck panther Kapa.ai is still learning and improving, please let me know how I did by reacting below.

stuck panther
#

@tropic ether this is what the inside of the markdown file is lie

{% table %}
- Date
- Course Name
- Course Code
- Discipline Name
- 
---
- 03/05/24
- Name test
- ge-104
- BS-iT
- 
---
- 
- 
- 
- 
- 
{% /table %}
tropic etherBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

The syntax you're using in your markdown file doesn't seem to be standard Markdown syntax for tables. In Markdown, tables are created using pipes (|) and hyphens (-). Here's an example:

| Date      | Course Name | Course Code | Discipline Name |
|-----------|-------------|-------------|-----------------|
| 03/05/24  | Name test   | ge-104      | BS-iT           |

This will render as a table in Markdown.

Astro supports GitHub Flavored Markdown, which includes table syntax. You can check out the Markdown Guide's Cheat Sheet (https://www.markdownguide.org/cheat-sheet/) for a quick overview of all the Markdown syntax elements, including tables.

If you're using a specific CMS or plugin that uses a different syntax for tables, you'll need to refer to their specific documentation or convert the table to standard Markdown syntax.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@stuck panther Kapa.ai is still learning and improving, please let me know how I did by reacting below.

stuck panther
#

@tropic ether can you tell me how to fix it?

tropic etherBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

To fix the issue, you need to change the syntax of your table to the standard Markdown syntax. Here's how you can do it:

Replace your current table syntax:

{% table %}
- Date
- Course Name
- Course Code
- Discipline Name
- 
---
- 03/05/24
- Name test
- ge-104
- BS-iT
- 
---
- 
- 
- 
- 
- 
{% /table %}

With the standard Markdown table syntax:

| Date      | Course Name | Course Code | Discipline Name |
|-----------|-------------|-------------|-----------------|
| 03/05/24  | Name test   | ge-104      | BS-iT           |

You can add more rows to the table by repeating the pattern. For example:

| Date      | Course Name | Course Code | Discipline Name |
|-----------|-------------|-------------|-----------------|
| 03/05/24  | Name test   | ge-104      | BS-iT           |
| 03/06/24  | Another test| ge-105      | BS-CS           |

This should render correctly as a table in your Markdown file.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@stuck panther Kapa.ai is still learning and improving, please let me know how I did by reacting below.

stuck panther
#

@tropic ether when i post images in my markdoc body it creats a folder of the same name as my markdoc file slug and within it put the images next tothe markdoc file. but im getting this error Could not resolve image "360_F_543063338_ykf0De29YEwKMb2X4wktTwSQpE3uz8X5.jpg" from "D:\github\studylane\src\content\noticeboard\examination-2nd-semester-2023-27.mdoc". Does the file exist?

tropic etherBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

The error message you're seeing, Could not resolve image "360_F_543063338_ykf0De29YEwKMb2X4wktTwSQpE3uz8X5.jpg" from "D:\\github\\studylane\\src\\content\\noticeboard\\examination-2nd-semester-2023-27.mdoc". Does the file exist?, indicates that Astro is unable to find the image file at the specified path.

Here are a few things you can check to resolve this issue:

  1. Check the file path: Make sure the image file is in the correct location relative to your .mdoc file. If your image is in the same folder as your .mdoc file, you should be able to reference it with a path starting with ./, like ./360_F_543063338_ykf0De29YEwKMb2X4wktTwSQpE3uz8X5.jpg.

  2. Check the file name: Ensure the file name is correct and that it matches exactly with the name in your .mdoc file. File names are case-sensitive, so make sure the case matches as well.

  3. Check the file extension: Make sure the image file has the correct extension. If your image is a JPEG, the extension should be .jpg.

  4. Use import for local images: If you're using Astro's default image services, the src parameter for Image and getImage must be either an imported image or a URL. It cannot be a string of a filepath. For local images, you can use the import statement to import the image and then use it in your Image or getImage function. Here's an example:

import myImage from "./360_F_543063338_ykf0De29YEwKMb2X4wktTwSQpE3uz8X5.jpg";

<Image src={myImage} alt="Cool image" />
stuck panther
#

@tropic ether i can not import the iamge as it's path is give by the keystatic on the markdoc file wahat to do?

tropic etherBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

If you're using Keystatic as your CMS and the image path is provided in the Markdoc file, you might need to override the default image node in Astro to handle the image paths dynamically.

Astro provides a way to override the default image node and render a custom Astro component in its place. You can create a custom MarkdocImage.astro component to pass the required src and alt properties from your image to the <Image /> component.

Here's an example of how you can do this:

---import { Image } from "astro:assets";
interface Props {  
  src: ImageMetadata | string;  
  alt: string;
}
const { src, alt } = Astro.props;---
<Image src={src} alt={alt} />{  typeof src === 'string' ? <img src={src} alt={alt} /> : <Image src={src} alt={alt} />}

In the above code, if the src is a string (which would be the case if it's a path provided by Keystatic), it will render a standard HTML <img> tag. If it's an ImageMetadata object (which would be the case if it's an image imported in Astro), it will use the <Image /> component from Astro.

You can then configure Markdoc to use this custom component to render images:

import { defineMarkdocConfig, nodes, component } from '@astrojs/markdoc/config';
export default defineMarkdocConfig({  
  nodes: {    
    image: {      
      ...nodes.image, // Apply Markdoc's defaults for other options      
      render: component('./src/components/MarkdocImage.astro'),    
    },  
  },
});

This way, the native image syntax in any .mdoc file will use the <Image /> component to optimize your local images. Remote images may still be used, but will not be rendered by Astro’s <Image /> component.

#

@stuck panther Kapa.ai is still learning and improving, please let me know how I did by reacting below.

stuck panther
#

@tropic ether in the markdoc the paht to image is 360_F_543063338_ykf0De29YEwKMb2X4wktTwSQpE3uz8X5.jpg while the image is in the same name folder /content/360_F_543063338_ykf0De29YEwKMb2X4wktTwSQpE3uz8X5.jpg

tropic etherBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

If the image is in the same folder as your Markdoc file, you should be able to reference it with a path starting with ./, like ./360_F_543063338_ykf0De29YEwKMb2X4wktTwSQpE3uz8X5.jpg.

However, if the image path is provided by Keystatic and you can't modify it, you might need to adjust your project structure or use a custom solution to resolve the image paths correctly.

One possible solution is to create a custom Astro component to handle the image paths dynamically. Here's an example of how you can do this:

---import { Image } from "astro:assets";
interface Props {  
  src: ImageMetadata | string;  
  alt: string;
}
const { src, alt } = Astro.props;---
<Image src={src} alt={alt} />{  typeof src === 'string' ? <img src={`./${src}`} alt={alt} /> : <Image src={src} alt={alt} />}

In the above code, if the src is a string (which would be the case if it's a path provided by Keystatic), it will render a standard HTML <img> tag with the path prefixed with ./.

You can then configure Markdoc to use this custom component to render images:

import { defineMarkdocConfig, nodes, component } from '@astrojs/markdoc/config';
export default defineMarkdocConfig({  
  nodes: {    
    image: {      
      ...nodes.image, // Apply Markdoc's defaults for other options      
      render: component('./src/components/MarkdocImage.astro'),    
    },  
  },
});

This way, the native image syntax in any .mdoc file will use the <Image /> component to optimize your local images. Remote images may still be used, but will not be rendered by Astro’s <Image /> component.