使用 ASP.NET MVC 编写的博客引擎的主题选择器想法

发布于 2024-12-12 03:54:06 字数 480 浏览 0 评论 0原文

我已经开始构建一个完全不专业的博客引擎,并且不打算被任何人使用。所以,用简单的英语来说,我不能告诉你,你继续为自己运行这个,你会很高兴。

您可能会看到我到目前为止编写的完整代码:

https://github.com/tugberkugurlu/MvcBloggy

虽然现在我正在从事DAL工作,但我也尝试制定我需要做的事情。我被困在这里的一点是我如何处理博客引擎的主题选择。

  • 我应该如何开始构建基础知识?我应该创建一个 html 框架并让其他人编写 CSS 并基本上选择它吗?或者其他什么?
  • 就 ASP.NET MVC 结构而言,处理此功能的最佳方法是什么?

我不确定到目前为止你们中是否有人做过类似的事情。如果您能提供方法,我将不胜感激。

I have started to build a blog engine which is totally unprofesional and meant to be not used by anyone. So, in plain English I cannot tell that you go ahead and run this for yourself and you will be happy.

You may see the complete code I have written so far :

https://github.com/tugberkugurlu/MvcBloggy

While now I am working on DAL, I also try to lay down what I need to do. One point I am stuck here is how I can handle theme selection for the blog engine.

  • How should I start building the basics? Should I create a skeleton html and let others write the CSS and basically select that? Or something else?
  • In terms of ASP.NET MVC structure, what would be the best approach to handle this feature.

I am not sure any of you guys has ever done something like this so far. I would appreciate if you can provide a way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

染火枫林 2024-12-19 03:54:07

我建议你看看NBlog temable博客引擎

https://github.com/ChrisFulstow/ NBlog

特别是,请查看类 ThemeableRazorViewEngine.cs

https://github.com/ChrisFulstow/NBlog/blob /master/NBlog.Web/Application/Infrastruct/ThemeableRazorViewEngine.cs

using System.Web.Mvc;
using NBlog.Web.Application.Service;

namespace NBlog.Web.Application.Infrastructure
{
public class ThemeableRazorViewEngine : RazorViewEngine
{
    private readonly IThemeService _themeService;

    public ThemeableRazorViewEngine(IThemeService themeService)
    {
        _themeService = themeService;

        base.ViewLocationFormats = new[]
        {
            _themeService.Current.BasePath + "/Views/{1}/{0}.cshtml",
            _themeService.Current.BasePath + "/Views/Shared/{0}.cshtml",
            "~/Themes/Default/Views/{1}/{0}.cshtml"                
        };

        base.PartialViewLocationFormats = new string[] {
            _themeService.Current.BasePath + "/Views/{1}/{0}.cshtml",
            _themeService.Current.BasePath + "/Views/Shared/{0}.cshtml",
            "~/Themes/Default/Views/Shared/{0}.cshtml"
        };
    }

    public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
    {           
        // bypass the view cache, the view will change depending on the current theme
        const bool useViewCache = false;

        return base.FindView(controllerContext, viewName, masterName, useViewCache);
    }
}
}

I suggest you to look at NBlog temable blog engine

https://github.com/ChrisFulstow/NBlog

In particular, look at the class ThemeableRazorViewEngine.cs

https://github.com/ChrisFulstow/NBlog/blob/master/NBlog.Web/Application/Infrastructure/ThemeableRazorViewEngine.cs

using System.Web.Mvc;
using NBlog.Web.Application.Service;

namespace NBlog.Web.Application.Infrastructure
{
public class ThemeableRazorViewEngine : RazorViewEngine
{
    private readonly IThemeService _themeService;

    public ThemeableRazorViewEngine(IThemeService themeService)
    {
        _themeService = themeService;

        base.ViewLocationFormats = new[]
        {
            _themeService.Current.BasePath + "/Views/{1}/{0}.cshtml",
            _themeService.Current.BasePath + "/Views/Shared/{0}.cshtml",
            "~/Themes/Default/Views/{1}/{0}.cshtml"                
        };

        base.PartialViewLocationFormats = new string[] {
            _themeService.Current.BasePath + "/Views/{1}/{0}.cshtml",
            _themeService.Current.BasePath + "/Views/Shared/{0}.cshtml",
            "~/Themes/Default/Views/Shared/{0}.cshtml"
        };
    }

    public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
    {           
        // bypass the view cache, the view will change depending on the current theme
        const bool useViewCache = false;

        return base.FindView(controllerContext, viewName, masterName, useViewCache);
    }
}
}
别再吹冷风 2024-12-19 03:54:07

完全主题化 Web 应用程序是一个非常复杂的问题。在拥有一个可用的博客引擎之前,您甚至不应该尝试解决它。

一个简单且相当容易实现的定制是允许用户选择 .css 文件,并确保页面中的所有元素都可以使用适当的 ID/类轻松寻址/选择。

Fully theming web application is a very complex problem. You should not even attempt solving it, before you have a functional blog engine.

A simple and reasonably easy to achieve customization, is allowing the user to pick the .css file, and making sure all elements within the page are easily addressable/selectable with the appropriate IDs/classes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文