Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks
jdgamble555 opened this issue Apr 13, 2024 · 0 comments
Open
2 tasks
Labels
enhancement New feature or request

Comments

@jdgamble555
Copy link

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

  • Yes
  • No
@jdgamble555 jdgamble555 added the enhancement New feature or request label Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant