Ejemplo n.º 1
0
        public void GenerateSite(ReadWritePaths rootPath, string baseUrl, string editBaseUrl)
        {
            var tags = parser.GetTags(rootPath.ReadPath);

            CopyImmutableFiles(rootPath);
            mutator.Mutate(rootPath, tags, baseUrl, editBaseUrl);
            AllArticlesPage(rootPath.WritePath, tags, baseUrl);
            TagPages(rootPath.WritePath, tags, baseUrl);
            AllTagsPage(rootPath.WritePath, tags, baseUrl);
        }
Ejemplo n.º 2
0
        public void Mutate(ReadWritePaths rootFilePath, TagCollection tags, string baseUrl, string editBaseUrl)
        {
            var di    = new DirectoryInfo(rootFilePath.ReadPath);
            var files = di.EnumerateFiles("*.md", SearchOption.AllDirectories).ToList();

            var output = MarkDownMutatorCore.MutateFile(rootFilePath, tags, baseUrl, editBaseUrl, files, contentGenerator);

            foreach (var inf in output)
            {
                filesystemRepository.WriteFile(inf.Path, inf.Content, inf.Title);
            }
        }
Ejemplo n.º 3
0
        void CopyImmutableFiles(ReadWritePaths rootPath)
        {
            var di = new DirectoryInfo(rootPath.ReadPath);

            foreach (var path in di.EnumerateFiles("*.*", SearchOption.AllDirectories))
            {
                if (IsToCopy(path) && !path.FullName.StartsWith(rootPath.WritePath))
                {
                    var relativePath = path.FullName.Substring(rootPath.ReadPath.Length);
                    filesystemRepository.Copy(path.FullName, Path.Combine(rootPath.WritePath, relativePath));
                }
            }
        }
Ejemplo n.º 4
0
        static List <Tuple <FileInfo, string, string> > GetTop4NewestFiles(ReadWritePaths rootFilePath, List <FileInfo> files)
        {
            var startIndex = rootFilePath.ReadPath.Length;

            return(files
                   .Where(x => x.FullName.StartsWith(Path.Combine(rootFilePath.ReadPath, "Articles")))
                   .OrderByDescending(x => x.LastWriteTime)
                   .Select(x => new { File = x, Content = File.ReadAllText(x.FullName) })
                   .Where(x => !DocumentParserCore.IsDraftFile(x.Content))
                   .Take(4)
                   .Select(x =>
                           Tuple.Create(
                               x.File,
                               x.File.FullName.Substring(startIndex, x.File.FullName.Length - startIndex - 2) + "html",
                               x.Content))
                   .ToList());
        }
Ejemplo n.º 5
0
        internal static IEnumerable <DocumentInfo> MutateFile(ReadWritePaths rootFilePath, TagCollection tags, string baseUrl, string editBaseUrl, List <FileInfo> files, ContentGenerator contentGenerator)
        {
            var top4files    = GetTop4NewestFiles(rootFilePath, files);
            int articleCount = tags.SelectMany(x => x.Value).Distinct().Count();

            foreach (var path in files)
            {
                var fileContent = File.ReadAllText(path.FullName, new UTF8Encoding(true));

                if (DocumentParserCore.IsDraftFile(fileContent))
                {
                    continue;
                }

                var relativePath = path.FullName.Substring(rootFilePath.ReadPath.Length).Replace('\\', '/');
                var editUrl      = editBaseUrl + relativePath;

                fileContent = MutateTopXArticles(fileContent, top4files, baseUrl);
                fileContent = MutateArticleHeaderUrlsTag(fileContent);
                fileContent = MutateSocialLinks(fileContent, baseUrl, relativePath);
                fileContent = MutateCommentText(fileContent, editUrl);
                fileContent = MutateCategoryTags(fileContent, baseUrl, contentGenerator);
                fileContent = MutateAllTagsLine(fileContent, tags, baseUrl, contentGenerator);
                fileContent = MutateBaseUrlTag(fileContent, baseUrl);
                fileContent = MutateGithubPageUrlTag(fileContent, editUrl);
                fileContent = MutateTagArticleCount(fileContent, articleCount);

                var title = DocumentParserCore.ParsePageTitle(fileContent);

                yield return
                    (new DocumentInfo()
                {
                    Content = fileContent,
                    Path = Path.Combine(rootFilePath.WritePath, relativePath),
                    Title = title
                });
            }
        }