正在做一个网站~要求实现整站的全静态~包括首页和栏目首页~而且各个栏目页面存放的文件夹是可以动态更改的~内页的文件名也是后台中定义的~
想问一下有没有什么好的整站生成策略以及个别内页内容的更新策略
模板标签替换已经实现了~~现在的问题是生成的整个站点的结构以及对这个结构的更新处理不好~~头大~~举个例子~~
我现在修改了一个内页的标题和内容~我要采用什么策略来更新与这个内页相关的栏目首页、栏目列表页、整站首页以及与它处于同一级的带有“上一篇文章”/“下一篇文章”这类链接的其它内页~~~程序如何知道应该重新生成哪些相关的页面呢?注:服务器在国外,访问速度比较慢而且站点的数据量比较大,肯定不能动不动就重新生成整站或整个栏目,所以想请各位高人给出一个合理的更新策略。能附上点源代码更好:)先谢谢各位了!!!小弟在线等待各位高见……
想问一下有没有什么好的整站生成策略以及个别内页内容的更新策略
模板标签替换已经实现了~~现在的问题是生成的整个站点的结构以及对这个结构的更新处理不好~~头大~~举个例子~~
我现在修改了一个内页的标题和内容~我要采用什么策略来更新与这个内页相关的栏目首页、栏目列表页、整站首页以及与它处于同一级的带有“上一篇文章”/“下一篇文章”这类链接的其它内页~~~程序如何知道应该重新生成哪些相关的页面呢?注:服务器在国外,访问速度比较慢而且站点的数据量比较大,肯定不能动不动就重新生成整站或整个栏目,所以想请各位高人给出一个合理的更新策略。能附上点源代码更好:)先谢谢各位了!!!小弟在线等待各位高见……
namespace EFPlatform_CodeGenerator
{
public partial class _Default : System.Web.UI.Page
{
private string outputPath;
private string categoryFileName;
private string productFileName;
private static DbProviderFactory dbFactory;
private DbConnection connection;
protected void Page_Load(object sender, EventArgs e)
{
outputPath = Server.MapPath("./");
categoryFileName = string.Format(@"{0}\Template\Category.html", outputPath);
productFileName = string.Format(@"{0}\Template\Product.html", outputPath);
string currentConnection = ConfigurationManager.AppSettings["Connection"];
ConnectionStringSettings css = ConfigurationManager.ConnectionStrings[currentConnection];
this.GetConnection(css);
}
private void GenerateCategory()
{
string template = Helper.ReadTextFile(categoryFileName);
Generator gen = new Generator(template);
gen.ParseTemplate();
Region rgnTitle = gen.Regions["Title"];
Region rgnCategory = gen.Regions["Category"];
Region rgnProducts = gen.Regions["Products"];
Region rgnNavigator = gen.Regions["Navigator"];
if (rgnTitle == null || rgnCategory == null || rgnProducts == null || rgnNavigator == null)
{
Response.Write("Missing region.");
return;
}
int categoryId;
string outputFileName;
DataView dvCategory = this.GetCategoryTable().DefaultView;
Pager pgrCategory = new Pager(1, dvCategory.Count);
for (int i = 0; i < pgrCategory.PageCount; i++)
{
rgnTitle.DataSource = (string)dvCategory[i]["CategoryName"]; //Use a string as data source
rgnCategory.DataSource = dvCategory[i]; //Use a DataRowView object as data source
pgrCategory.CurrentPage = i + 1;
rgnNavigator.DataSource = pgrCategory; //Use a Pager object as data source
categoryId = (int)dvCategory[i]["CategoryID"];
rgnProducts.DataSource = this.GetProductTable(categoryId); //Use a DataTable object as data souce
outputFileName = string.Format(@"{0}\Html\Category{1}.html", outputPath, categoryId);
Helper.WriteTextFile(outputFileName, gen.Generate());
}
}
private void GenerateProduct()
{
string template = Helper.ReadTextFile(productFileName);
Generator gen = new Generator(template);
gen.ParseTemplate();
Region rgnTitle = gen.Regions["Title"];
Region rgnProduct = gen.Regions["Product"];
Region rgnNavigator = gen.Regions["Navigator"];
if (rgnTitle == null || rgnProduct == null || rgnNavigator == null)
{
Response.Write("Missing region.");
return;
}
string outputFileName;
List<Product> productList = this.GetProductList();
Pager pgrProduct = new Pager(1, productList.Count);
for (int i = 0; i < pgrProduct.PageCount; i++)
{
rgnTitle.DataSource = productList[i].CategoryName; //Use a string as data source
rgnProduct.DataSource = productList[i]; //Use a Product object as data source
pgrProduct.CurrentPage = i + 1;
rgnNavigator.DataSource = pgrProduct; //Use a Pager object as data source
outputFileName = string.Format(@"{0}\Html\Product{1}.html", outputPath, productList[i].ProductID);
Helper.WriteTextFile(outputFileName, gen.Generate());
}
} #region DataSourcePreparing
private void GetConnection(ConnectionStringSettings css)
{
if (dbFactory == null)
{
dbFactory = DbProviderFactories.GetFactory(css.ProviderName);
}
this.connection = dbFactory.CreateConnection();
this.connection.ConnectionString = css.ConnectionString;
}
private DataTable GetCategoryTable()
{
string commandText = "SELECT CategoryID, CategoryName, Description FROM Categories";
DbDataAdapter da = dbFactory.CreateDataAdapter();
da.SelectCommand = dbFactory.CreateCommand();
da.SelectCommand.Connection = this.connection;
da.SelectCommand.CommandText = commandText;
DataTable dt = new DataTable();
this.connection.Open();
da.Fill(dt);
this.connection.Close();
return dt;
}
private DataTable GetProductTable(int categoryId)
{
string commandText = string.Format("SELECT * FROM Products WHERE CategoryID = {0}", categoryId);
DbDataAdapter da = dbFactory.CreateDataAdapter();
da.SelectCommand = dbFactory.CreateCommand();
da.SelectCommand.Connection = this.connection;
da.SelectCommand.CommandText = commandText;
DataTable dt = new DataTable();
this.connection.Open();
da.Fill(dt);
this.connection.Close();
return dt;
}
private List<Product> GetProductList()
{
string commandText = "SELECT p.*, c.CategoryName, s.CompanyName FROM (Products AS p INNER JOIN Categories AS c ON p.CategoryID = c.CategoryID) INNER JOIN Suppliers AS s ON p.SupplierID = s.SupplierID ORDER BY p.ProductID";
DbCommand command = this.connection.CreateCommand();
command.CommandText = commandText;
List<Product> productList = new List<Product>();
Product product;
this.connection.Open();
using (DbDataReader dr = command.ExecuteReader())
{
while (dr.Read())
{
product = new Product();
Helper.FillModel(product, dr);
productList.Add(product);
}
}
this.connection.Close();
return productList;
}
protected void Button1_Click(object sender, EventArgs e)
{
this.GenerateCategory();
}
protected void Button2_Click(object sender, EventArgs e)
{
this.GenerateProduct();
}
}
}
{
string url = "http://" + Request.Url.Authority + "/default.aspx";
new System.Net.WebClient().DownloadFile(url, Server.MapPath("~/default.html"));
Response.Redirect("default.html"); Response.Write(Request.Url.DnsSafeHost);
}
这个站目前用的是虚拟主机,内存和其它的硬件配置我也动不了~~但是用iframe是要考虑一下了~~还有就是这个站规模比较大而且文件存放的路径都是自定义的,管理起来很麻烦~~基本上就是一个栏目固定的通用CMS了~~~感谢你的回答!To:dyjqk
兄台给出来的是生成页面的代码~这个我已经实现了,我需要的是文件存储结构方面的逻辑或者思路。还有就是在添加、编辑或删除过程中重新生成相关文件的逻辑和思路~~~~也感谢你的回答!