analogjs / analog

The fullstack meta-framework for Angular. Powered by Vite and Nitro
https://analogjs.org
MIT License
2.5k stars 240 forks source link

Allow usage of injectContentFiles and injectContent outside of Content Directory #1034

Closed jdgamble555 closed 1 month ago

jdgamble555 commented 5 months ago

Which scope/s are relevant/related to the feature request?

create-analog

Information

Currently there is no way to get the file contents in your pages directory for .md files. This is particularly useful when you want to display a list of md files for a pages subdirectory on another page. I would think I could use injectContentFiles or injectContent to do this, but it only covers the content directory.

My suggestion would be to depreciate both of them, and rename then to injectMarkdownFiles and injectMarkdown respectively (or some other directory inclusive name), as that is what they are for.

Here is discord link for reference - https://discord.com/channels/994618831987290112/1226646912422383707

Describe any alternatives/workarounds you're currently using

I created a custom resolver, but I shouldn't have to do this manually.

import { ResolveFn } from '@angular/router';

function getSlug(filename: string) {
  const parts = filename.match(/^(\\|\/)(.+(\\|\/))*(.+)\.(.+)$/);
  return parts?.length ? parts[4] : '';
}

export const indexResolver: ResolveFn<any> = async () => {

  const data = import.meta.glob('/src/app/pages/blog/*.md', {
    eager: true,
    import: 'default',
    query: { 'analog-content-list': true },
  });

  return Object.keys(data).map((filename) => {
    const attributes = data[filename] as any;
    const slug = attributes['slug'];

    return {
      filename: filename.split('/').pop()?.split('.')[0],
      attributes,
      slug: slug ? encodeURI(slug) : encodeURI(getSlug(filename)),
    };
  });
};

I would be willing to submit a PR to fix this issue

brandonroberts commented 1 month ago

Closed by https://github.com/analogjs/analog/pull/1228