如何使用ASP.NET MVC将使用GrapeJS汇编的页面保存到数据库中

问题描述

好吧,我正在使用ASP.NET MVC开发自己的内容管理系统,对于页面构建器,我决定使用GrapeJS。现在,由于这对我来说是新事物,所以我似乎无法找到一种方法来保存使用GrapeJS汇编的页面。我使用了gjs-preset-webpage GrapeJS插件,而我拥有的唯一组装区域的JavaScript如下所示:

<script type="text/javascript">
        var editor = grapesjs.init({
        height: '100%',showOffsets: 1,noticeOnUnload: 0,storageManager: { autoload: 0 },container: '#gjs',fromElement: true,plugins: ['gjs-preset-webpage'],pluginsOpts: {
            'gjs-preset-webpage': {}
        }
    });
   </script>

我使用的HTML如下:

<div id="gjs" style="height:0px; overflow:hidden">
    <div class="panel">
        <h1 class="welcome">Welcome to</h1>
        <div class="big-title">
            <svg class="logo" viewBox="0 0 100 100">
                <path d="M40 5l-12.9 7.4 -12.9 7.4c-1.4 0.8-2.7 2.3-3.7 3.9 -0.9 1.6-1.5 3.5-1.5 5.1v14.9 14.9c0 1.7 0.6 3.5 1.5 5.1 0.9 1.6 2.2 3.1 3.7 3.9l12.9 7.4 12.9 7.4c1.4 0.8 3.3 1.2 5.2 1.2 1.9 0 3.8-0.4 5.2-1.2l12.9-7.4 12.9-7.4c1.4-0.8 2.7-2.2 3.7-3.9 0.9-1.6 1.5-3.5 1.5-5.1v-14.9 -12.7c0-4.6-3.8-6-6.8-4.2l-28 16.2" />
            </svg>
            <span>GrapesJS</span>
        </div>
        <div class="description">
            This is a demo content from index.html. For the development,you shouldn't edit this file,instead you can
            copy and rename it to _index.html,on next server start the new file will be served,and it will be ignored by git.
        </div>
    </div>
    <style>
        .panel {
            width: 90%;
            max-width: 700px;
            border-radius: 3px;
            padding: 30px 20px;
            margin: 150px auto 0px;
            background-color: #d983a6;
            Box-shadow: 0px 3px 10px 0px rgba(0,0.25);
            color: rgba(255,255,0.75);
            font: caption;
            font-weight: 100;
        }

        .welcome {
            text-align: center;
            font-weight: 100;
            margin: 0px;
        }

        .logo {
            width: 70px;
            height: 70px;
            vertical-align: middle;
        }

            .logo path {
                pointer-events: none;
                fill: none;
                stroke-linecap: round;
                stroke-width: 7;
                stroke: #fff
            }

        .big-title {
            text-align: center;
            font-size: 3.5rem;
            margin: 15px 0;
        }

        .description {
            text-align: justify;
            font-size: 1rem;
            line-height: 1.5rem;
        }
    </style>
</div> 

现在,我已经将其嵌入到项目中并且可以使用它来汇编页面了,我似乎找不到如何保存或将汇编页面保存到什么地方。谁能帮我吗?

解决方法

您需要一个端点,以允许Grapes的存储管理员发送站点的当前状态信息。我保存了json和html以防万一,但是我认为json就足够了。好了,那么您就可以设置存储管理器了。

private String abbreviate(String s){
  if(s.length() <= 10) return s;
  return s.substring(0,8) + ".." ;
}

每次使用以下参数进行更改时,您都会呼叫端点:

  • const editor = grapesjs.init({ storageManager:{ type: 'remote',autosave: true,// Store data automatically urlStore: 'YOUR_ENDPOINT_URL',} }); :资产数组
  • gjs-assets:带有您网站标记定义的对象
  • gjs-components:具有样式定义的对象
  • gjs-styles:您的网站HTML
  • gjs-html:您的CSS

在初始化葡萄时也请务必注入以下定义:

gjs-css

有关更多信息:Docs