예제 #1
0
        private object GetDataOrFolder(string name)
        {
            var itemPath = Path.Combine(this._path, name);

            // check cache
            string cacheKey = "data:" + itemPath;
            object result = Site.GetFromCache(cacheKey);
            if (result != null)
            {
                return result;
            }

            string cacheDependencyPath = null;
            if (Directory.Exists(itemPath))
            {
                result = new DataFolder(itemPath);
                cacheDependencyPath = itemPath;
            }
            else if (File.Exists(itemPath + ".yml"))
            {
                var yaml = File.ReadAllText(itemPath + ".yml");
                result = Site.YamlToObject(yaml);
                cacheDependencyPath = itemPath + ".yml";
            }
            else
            {
                // unknown data type
                return null;
            }

            // put to cache
            Site.AddToCache(cacheKey, result, new string[] { cacheDependencyPath }, null);

            return result;
        }
예제 #2
0
파일: Site.cs 프로젝트: mteper/website
        private static void LoadSite()
        {
            _siteRoot = HttpContext.Current.Server.MapPath(SITE_VROOT).TrimEnd('\\'); // e.g. C:\website

            cacheDependencyDirectories.Clear();

            _pages.Clear();
            _layouts.Clear();
            _collections.Clear();

            // load _config.yml
            _site = LoadSiteConfig();

            // site URL
            _site["url"] = HttpContext.Current.Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);

            // load site data
            _site["data"] = new DataFolder(GetPath(DATA_FOLDER));

            // load site pages (without content)
            LoadSiteContent("");

            // all pages
            _site["pages"] = _pages.Values.ToList();

            // collections
            foreach (var collection in _collections)
            {
                var sortedCollection = collection.Value.OrderByDescending(p => p.Date).ToList();

                // set Next and Previous
                for (int i = 0; i < sortedCollection.Count; i++)
                {
                    // Previous
                    if (i < sortedCollection.Count - 1)
                    {
                        sortedCollection[i].Previous = sortedCollection[i + 1];
                    }
                    // Next
                    if (i > 0)
                    {
                        sortedCollection[i].Next = sortedCollection[i - 1];
                    }
                }
                _site[collection.Key] = sortedCollection;
            }

            // group pages by categories
            var categories = from page in _pages.Values
                             from category in page.Categories
                             group page by category;

            var categoriesHash = new Dictionary<string, object>();
            foreach (var category in categories)
            {
                categoriesHash[category.Key] = category.ToList();
            }
            _site["categories"] = categoriesHash;

            // group pages by tags
            var tags = from page in _pages.Values
                       from tag in page.Tags
                       group page by tag;

            var tagsHash = new Dictionary<string, object>();
            foreach (var tag in tags)
            {
                tagsHash[tag.Key] = tags.ToList();
            }
            _site["tags"] = tagsHash;

            // add resource bundles
            _site["bundles"] = new Dictionary<string, object>
            {
                { "css", Styles.Render("~/site-css").ToString() },
                { "js", Scripts.Render("~/site-js").ToString() }
            };
        }
예제 #3
0
파일: Site.cs 프로젝트: inochikawa/website
        private static void LoadSite()
        {
            _siteRoot = HttpContext.Current.Server.MapPath(SITE_VROOT).TrimEnd('\\'); // e.g. C:\website

            cacheDependencyDirectories.Clear();

            _pages.Clear();
            _layouts.Clear();
            _collections.Clear();

            // load _config.yml
            _site = LoadSiteConfig();

            // site URL
            _site["url"] = HttpContext.Current.Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);

            // load site data
            _site["data"] = new DataFolder(GetPath(DATA_FOLDER));

            // load site pages (without content)
            LoadSiteContent("");

            // all pages
            _site["pages"] = _pages.Values.ToList();

            // collections
            foreach (var collection in _collections)
            {
                var sortedCollection = collection.Value.OrderByDescending(p => p.Date).ToList();

                // set Next and Previous
                for (int i = 0; i < sortedCollection.Count; i++)
                {
                    // Previous
                    if (i < sortedCollection.Count - 1)
                    {
                        sortedCollection[i].Previous = sortedCollection[i + 1];
                    }
                    // Next
                    if (i > 0)
                    {
                        sortedCollection[i].Next = sortedCollection[i - 1];
                    }
                }
                _site[collection.Key] = sortedCollection;
            }

            // group pages by categories
            var categories = from page in _pages.Values
                             from category in page.Categories
                             group page by category;

            var categoriesHash = new Dictionary <string, object>();

            foreach (var category in categories)
            {
                categoriesHash[category.Key] = category.ToList();
            }
            _site["categories"] = categoriesHash;

            // group pages by tags
            var tags = from page in _pages.Values
                       from tag in page.Tags
                       group page by tag;

            var tagsHash = new Dictionary <string, object>();

            foreach (var tag in tags)
            {
                tagsHash[tag.Key] = tags.ToList();
            }
            _site["tags"] = tagsHash;

            // add resource bundles
            _site["bundles"] = new Dictionary <string, object>
            {
                { "css", Styles.Render("~/site-css").ToString() },
                { "js", Scripts.Render("~/site-js").ToString() }
            };
        }