コード例 #1
0
ファイル: StructureService.cs プロジェクト: tidyui/statica
 /// <summary>
 /// Reloads the structure information.
 /// </summary>
 public Task Reload()
 {
     return(Task.Run(() =>
     {
         _structure = null;
     }));
 }
コード例 #2
0
ファイル: StructureService.cs プロジェクト: tidyui/statica
        /// <summary>
        /// Gets the page structure.
        /// </summary>
        /// <param name="sitemap"></param>
        /// <param name="path"></param>
        /// <param name="prefix"></param>
        /// <returns></returns>
        private IList <StaticPage> GetStructureItemsRecursive(StaticSitemap structure, string path, string prefix = "")
        {
            var items = new List <StaticPage>();

            foreach (var info in GetDirectoryItems(path))
            {
                if (info.Name != "Index.md")
                {
                    var item = new StaticPage
                    {
                        Title        = Utils.GenerateTitle(info),
                        Slug         = prefix + Utils.GenerateSlug(info),
                        Path         = info.FullName,
                        Created      = info.CreationTime,
                        LastModified = info.LastWriteTime
                    };

                    // Check if this is a directory
                    if (info is DirectoryInfo dir)
                    {
                        // Get the subitems
                        item.Items = GetStructureItemsRecursive(structure, dir.FullName, $"{item.Slug}/");

                        // Check if the directory has an index file
                        var index = dir.GetFiles("Index.md").FirstOrDefault();
                        if (index != null)
                        {
                            item.Path         = index.FullName;
                            item.Created      = index.CreationTime;
                            item.LastModified = index.LastWriteTime;
                        }
                        else if (item.Items.Count > 0)
                        {
                            item.Path     = null;
                            item.Redirect = item.Items[0].Slug;
                        }
                        else
                        {
                            continue;
                        }
                    }

                    structure.Routes[item.Slug] = item;
                    items.Add(item);
                }
            }
            return(items);
        }