private string GetEmbedCode(string path, string filename) { SiteFile file = SiteFiles.GetFile(path, filename); if (file != null) { if (!GlobalSettings.IsImage(filename)) { return(string.Format("<a href=\"{0}\">{1}</a>", FileStorageProvider.GetGenericDownloadUrl(file.File), filename)); } else { int width = 200; int height = 200; try { width = int.Parse(this.txtWidth.Text); } catch { } try { height = int.Parse(this.txtHeight.Text); } catch { } return(GlobalSettings.ResizeImageHtml(SiteUrlManager.GetResizedImageUrl(file.File, width, height), width, height, false)); } } else { return(string.Empty); } }
private async Task <Result <string> > SaveFileInfo(SiteFile entity) { db.Files.Add(entity); await db.SaveChangesAsync(); var fileUrl = StringUtils.ConvertToUrl(entity.FilePath); return(Result.Ok(fileUrl)); }
public static SiteFile Create(this SiteFile ignore, string content, string relativeFilePath, TemplateType sourceTemplateType, bool isEncoded) { return(new SiteFile() { Content = content, RelativeFilePath = relativeFilePath, SourceTemplateType = sourceTemplateType, IsBase64Encoded = isEncoded }); }
public IEnumerable <SiteFile> AllFiles(Site site, string path) { var storage = site.GetIsolatedStorage(_baseDir); List <SiteFile> list = new List <SiteFile>(); foreach (var item in storage.GetFileNames(path)) { SiteFile file = new SiteFile() { Site = site, Directory = path, FileName = item }; list.Add(file); } return(list); }
public static SiteFile Create(this SiteFile ignore, bool isEncoded) { string content; TemplateType templateType; if (isEncoded) { content = string.Empty.GetRandom(); templateType = TemplateType.Raw; } else { content = Convert.ToBase64String(string.Empty.GetRandom().Select(s => Convert.ToByte(s)).ToArray()); templateType = TemplateType.ContactPage; } return(ignore.Create(content, $"./{string.Empty.GetRandom()}", templateType, isEncoded)); }
public static SortedList <string, SiteFile> GetFilesFromConfig() { var collection = new SortedList <string, SiteFile>(1024); if (!File.Exists(cfgFileName)) { return(collection); } var lines = File.ReadAllLines(cfgFileName); foreach (var line in lines) { if (line.Trim().Length <= 0) { continue; } var sf = new SiteFile(line); if (!sf.fi.Exists) { continue; } if (!collection.ContainsKey(sf.FileName)) { collection.Add(sf.fi.FullName, sf); } else { Console.WriteLine("Error in file: duplicate entries for file " + sf.FileName); Console.WriteLine("Duplicated entries will be deleted"); } } return(collection); }
public static void AddNewFiles(SortedList <string, SiteFile> collection) { var e = Directory.EnumerateFiles(CurDir, "*", SearchOption.AllDirectories); foreach (var FileName in e) { if (collection.ContainsKey(FileName)) { continue; } var sf = new SiteFile("0.5: " + FileName); if (sf.fi.Name == "vsm.exe" || sf.fi.Name == cfgFileName || sf.fi.Name == cfgSite || sf.fi.Name == "robots.txt" || sf.relativeUrl.StartsWith(".")) { sf.forbidden = 1; } else { sf.priority = sf.calculatePriority(); } collection.Add(sf.fi.FullName, sf); } }
public static SiteFile Create(this SiteFile ignore) { return(ignore.Create(string.Empty.GetRandom(), $"./{string.Empty.GetRandom()}", Enumerations.TemplateType.ContentPage, false)); }
public IEnumerable <SiteFile> Build() { var result = new List <SiteFile>(); var pageGen = this.ServiceProvider.GetService <IPageGenerator>(); var contentItemPageGen = this.ServiceProvider.GetService <IContentItemPageGenerator>(); var homePageGen = this.ServiceProvider.GetService <IHomePageGenerator>(); var navProvider = this.ServiceProvider.GetService <INavigationProvider>(); var archiveProvider = this.ServiceProvider.GetService <IArchiveProvider>(); var contactProvider = this.ServiceProvider.GetService <IContactProvider>(); var searchProvider = this.ServiceProvider.GetService <ISearchProvider>(); var redirectProvider = this.ServiceProvider.GetService <IRedirectProvider>(); var syndicationProvider = this.ServiceProvider.GetService <ISyndicationProvider>(); var contentEncoder = this.ServiceProvider.GetService <IContentEncoder>(); var contentRepo = this.ServiceProvider.GetService <IContentRepository>(); var siteSettings = contentRepo.GetSiteSettings() ?? new SiteSettings(); var posts = contentRepo.GetAllPosts(); var pages = contentRepo.GetAllPages(); var widgets = contentRepo.GetAllWidgets(); var categories = contentRepo.GetCategories(); // Create Sidebar Content var rootLevelSidebarContent = pageGen.GenerateSidebarContent(posts, pages, widgets, "./"); var childLevelSidebarContent = pageGen.GenerateSidebarContent(posts, pages, widgets, "../"); // Create navbars var rootLevelNavigationContent = navProvider.CreateNavigation(pages, "./", siteSettings.OutputFileExtension); var childLevelNavigationContent = navProvider.CreateNavigation(pages, "../", siteSettings.OutputFileExtension); // Create bootstrap file var bootstrapFile = new SiteFile() { RelativeFilePath = $"./bootstrap.min.css", SourceTemplateType = Enumerations.TemplateType.Bootstrap, Content = pageGen.GenerateBootstrapPage() }; if (!string.IsNullOrEmpty(bootstrapFile.Content)) { result.Add(bootstrapFile); } // Create Style page result.Add(new SiteFile() { RelativeFilePath = $"./Style.css", SourceTemplateType = Enumerations.TemplateType.Style, Content = pageGen.GenerateStylesheet() }); // Create home page result.Add(new SiteFile() { RelativeFilePath = $"./index.html", SourceTemplateType = Enumerations.TemplateType.HomePage, Content = homePageGen.GenerateHomepage(rootLevelSidebarContent, rootLevelNavigationContent, posts) }); // Create Archive result.Add(new SiteFile() { RelativeFilePath = $"./archive.html", SourceTemplateType = Enumerations.TemplateType.Archive, Content = archiveProvider.GenerateArchive(posts, pages, rootLevelNavigationContent, rootLevelSidebarContent, "./") }); // Create Contact Page result.Add(new SiteFile() { RelativeFilePath = $"./contact.html", SourceTemplateType = Enumerations.TemplateType.ContactPage, Content = contactProvider.GenerateContactPage(rootLevelNavigationContent, rootLevelSidebarContent, "./") }); // Create RSS Feed var syndicationContent = syndicationProvider.GenerateFeed(posts); result.Add(new SiteFile() { RelativeFilePath = "./syndication.xml", SourceTemplateType = Enumerations.TemplateType.Syndication, Content = syndicationContent }); foreach (var post in posts) { // Add all published content pages to the results if (post.IsPublished) { if (string.IsNullOrWhiteSpace(post.Slug)) { post.Slug = contentEncoder.UrlEncode(post.Title); } // Add the post page String postFileName = $"{post.Slug}.{siteSettings.OutputFileExtension}"; String postFilePath = System.IO.Path.Combine("Posts", postFileName); var postPageTemplateType = Enumerations.TemplateType.PostPage; result.Add(new SiteFile() { RelativeFilePath = postFilePath, SourceTemplateType = postPageTemplateType, Content = contentItemPageGen.Generate(childLevelSidebarContent, childLevelNavigationContent, post, postPageTemplateType, "..", false) }); // Add the permalink page String permalinkFileName = $"{contentEncoder.HTMLEncode(post.Id.ToString())}.{siteSettings.OutputFileExtension}"; String permalinkFilePath = System.IO.Path.Combine("Permalinks", permalinkFileName); String redirectFilePath = $"../Posts/{postFileName}"; // System.IO.Path.Combine("..", postFilePath); result.Add(new SiteFile() { RelativeFilePath = permalinkFilePath, SourceTemplateType = Enumerations.TemplateType.Redirect, Content = redirectProvider.GenerateRedirect(redirectFilePath) }); } } foreach (var page in pages) { // Add all published content pages to the results if (page.IsPublished) { if (string.IsNullOrWhiteSpace(page.Slug)) { page.Slug = contentEncoder.UrlEncode(page.Title); } var contentPageTemplateType = Enumerations.TemplateType.ContentPage; result.Add(new SiteFile() { RelativeFilePath = $"Pages/{page.Slug}.{siteSettings.OutputFileExtension}", SourceTemplateType = contentPageTemplateType, Content = contentItemPageGen.Generate(childLevelSidebarContent, childLevelNavigationContent, page, contentPageTemplateType, "..", false) }); } } // Add Search Pages var tags = posts .Where(p => p.Tags.IsNotNull()) .SelectMany(p => p.Tags) .Distinct(); var categoryIds = posts.SelectMany(p => p.CategoryIds).Distinct(); var usedCategories = categories.Where(c => categoryIds.Contains(c.Id)); IEnumerable <string> usedCategoryNames = usedCategories.Any() ? usedCategories.Select(c => c.Name.ToLower()) : new List <String>(); var searchNames = new List <string>(); searchNames.AddRange(tags); searchNames.AddRange(usedCategoryNames); var distinctSearchTerms = searchNames .Distinct() .Where(t => !string.IsNullOrEmpty(t)); foreach (var name in distinctSearchTerms) { result.Add(new SiteFile() { Content = searchProvider.GenerateSearchResultsPage(name, posts, childLevelNavigationContent, childLevelSidebarContent, "../"), RelativeFilePath = $"Search/{contentEncoder.UrlEncode(name)}.{siteSettings.OutputFileExtension}", SourceTemplateType = Enumerations.TemplateType.SearchPage, IsBase64Encoded = false }); } // Add favicon.ico file if it exists var rootFiles = contentRepo.GetFolderContents("."); var faviconFile = rootFiles.SingleOrDefault(f => f.FileName == "favicon.ico"); if (faviconFile.IsNotNull()) { result.Add(new SiteFile() { RelativeFilePath = System.IO.Path.Combine("", faviconFile.FileName), SourceTemplateType = Enumerations.TemplateType.Raw, Content = System.Convert.ToBase64String(faviconFile.Contents), IsBase64Encoded = true }); } // Add files from Theme if there are any if (!string.IsNullOrWhiteSpace(siteSettings.Theme)) { String path = $".\\themes\\{siteSettings.Theme}"; var additionalFiles = contentRepo.GetFolderContents(path); foreach (var rawFile in additionalFiles) { result.Add(new SiteFile() { RelativeFilePath = System.IO.Path.Combine("Theme", rawFile.FileName), SourceTemplateType = Enumerations.TemplateType.Raw, Content = System.Convert.ToBase64String(rawFile.Contents), IsBase64Encoded = true }); } } // Add additional raw files if (siteSettings.AdditionalFilePaths.IsNotNull() && siteSettings.AdditionalFilePaths.Any()) { var additionalFiles = contentRepo.GetFoldersContents(siteSettings.AdditionalFilePaths); foreach (var rawFile in additionalFiles) { result.Add(new SiteFile() { RelativeFilePath = System.IO.Path.Combine(rawFile.RelativePath, rawFile.FileName), SourceTemplateType = Enumerations.TemplateType.Raw, Content = System.Convert.ToBase64String(rawFile.Contents), IsBase64Encoded = true }); } } return(result); }