【问题标题】:Pre Compiling HTML files for publication as static files [closed]预编译 HTML 文件以作为静态文件发布 [关闭]
【发布时间】:2012-02-14 01:56:41
【问题描述】:

我有一个项目,目前有大量技术规范以 HTML 文件的形式“发布”。 HTML 文件并非托管在 Web 服务器上,而是压缩并分发以从 PC 的本地文件系统访问。

我正在探索创建“发布”系统的想法,在该系统中发布者可以根据 HTML 本身中的自定义标签修改 HTML 文件的内容。如果它是基于服务器的,我想这类似于使用 PHP 或 ASP。

例如,我可以添加

<Publisher action="___" params="________" />

发布者会检测到“标签”的存在并进行必要的处理,然后将必要的 HTML 注入替换标签的文件中。

有没有人知道使用基于 .NET 的技术实现此目的的方法,或实现相同目的的另一种方法。

【问题讨论】:

  • 您可能可以为此使用 asp.net 视图引擎。

标签: .net html publishing precompile custom-tags


【解决方案1】:

好的,不确定这是否是最优雅的解决方案,它可以工作。

1) 基于Cannot delete directory with Directory.Delete(path, true),我清除了已发布“站点”的目标位置。

2) 然后,我使用基于问题Copy the entire contents of a directory in C# 的公认解决方案的代码复制所有文件。

3) 我截取所有“HTM”或“HTML”文件并使用正则表达式查看是否需要任何“处理”。这是基于来自站点的代码http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.replace(v=vs.71).aspx(如下所示)

using System.Text.RegularExpressions;

class RegExSample 
{
   static string CapText(Match m) 
   {
     // Get the matched string.
     string x = m.ToString();
     // If the first char is lower case...
     if (char.IsLower(x[0])) 
     {
        // Capitalize it.
       return char.ToUpper(x[0]) + x.Substring(1, x.Length-1);
     }
     return x;
   }

   static void Main() 
   {
     string text = "four score and seven years ago";
     System.Console.WriteLine("text=[" + text + "]");
     string result = Regex.Replace(text, @"\w+",
        new MatchEvaluator(RegExSample.CapText));
     System.Console.WriteLine("result=[" + result + "]");
   }
}

【讨论】:

    猜你喜欢
    • 2018-01-20
    • 2012-03-21
    • 2015-08-08
    • 2017-08-09
    • 1970-01-01
    • 2015-03-09
    • 2018-04-19
    • 2012-04-09
    • 1970-01-01
    相关资源
    最近更新 更多