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

Proposals on formation Title and Slug for StaticPage. #2

Open
InfDev opened this issue May 20, 2020 · 3 comments
Open

Proposals on formation Title and Slug for StaticPage. #2

InfDev opened this issue May 20, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@InfDev
Copy link

InfDev commented May 20, 2020

Sample implementation to remove restrictions:

  • Slug in English only
  • Sequence number only 2 digits

Class SlugService taken from the project OrchardCore

        private IList<StaticPage> GetStructureItemsRecursive(StaticSitemap structure, string path, string prefix = "")
        {
            var items = new List<StaticPage>();
            var slugService = new SlugService();
            foreach (var info in GetDirectoryItems(path))
            {
                if (info.Name != "Index.md")
                {
                    var title = info is DirectoryInfo ? info.Name : Path.GetFileNameWithoutExtension(info.Name);
                    var indexSpace = title.IndexOf(' ');
                    if (indexSpace >= 0)
                        title = title.Substring(indexSpace + 1);
                    var slug = slugService.Slugify(title);
                    var item = new StaticPage
                    {
                        Title = title, // Utils.GenerateTitle(info),
                        Slug = prefix + slug, // Utils.GenerateSlug(info),
                        Path = info.FullName,
                        Created = info.CreationTime,
                        LastModified = info.LastWriteTime
                    };
				}
				// ...
			}
			// ...
		}
@tidyui
Copy link
Owner

tidyui commented May 20, 2020

Cool, however I trying to keep dependencies at a bare minimum, actually thinking about dropping the dependency on Piranha as well. I see a couple of options here:

  1. We add a hook/extension point where you can exchange the current default behavior with the behavior you want, for example using services from OrchardCore if you're using that.
  2. We could add packages that does this out of the box and adds the extra integration for different host systems, for example offering the packages Statica, Statica.Piranha, Statica.OrchardCore and so on.

What do you think?

@tidyui tidyui added the enhancement New feature or request label May 20, 2020
@InfDev
Copy link
Author

InfDev commented May 20, 2020

A good idea. It is enough to exclude the module and registration in Piranha and make changes to

        public async Task<StaticPageModel> GetPageAsync(string slug)
        {
			// ...
                        using (var sr = new StreamReader(file.OpenRead()))
                        {
                            model.Markdown = await sr.ReadToEndAsync();
                            var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
                            // model.Body = App.Markdown.Transform(model.Markdown);
                            model.Body = Markdown.ToHtml(model.Markdown, pipeline);
                        }
			// ...
        }

And then even without integration modules it will integrate well into other systems.

@tidyui
Copy link
Owner

tidyui commented May 21, 2020

Yes I know 😀 I just wrote this code because I needed to plug it into our website, but I can definitely remove it so it can be integrated into other applications without the need to fork.

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

2 participants