编译模板

编译模板时,会为模板中站点的 structure.json 文件中的每个页创建一个静态 HTML 页。

编译步骤将页元数据(例如 100.json)与页布局(例如 about.html)相组合,这样您就有了一个可以立即显示的 HTML 页,而不需要在运行时使用控制器。使用定制编译器,可以通过将以前的动态项(例如导航和组件)编译到页中来进一步减少运行时 JavaScript 的执行。

cec compile-template 命令将对站点中的每个页执行以下操作:

  • 读取站点和页元数据
  • 读取页布局并应用任何页布局编译器
  • 对于页上的每个内容框:
    • 使用在 page.json 文件中定义的网格扩展内容框
    • 对于内容框中的每个组件:
      • 应用任何组件编译器
      • 将生成的组件标记插入内容框内的相应位置
  • 扩展编译的标记中的任何宏,并插入 Oracle Content Management 呈现器在运行时使用的 SCS JavaScript 对象
  • src/templates/<template>/static 文件夹下保存编译的页标记

要编译站点,请运行:

> cec compile-template BlogTemplate
Compile Template: compiling template BlogTemplate
Oracle Content Management Site Compiler

createPage: Processing pageId 100. Preview URL: 
http://localhost:8085/templates/BlogTemplate/index.html 
createPage: Processing pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail.html 
createPage: Processing pageId 401. Preview URL: 
http://localhost:8085/templates/BlogTemplate/about.html 
createPage: Processing pageId 402. Preview URL: 
http://localhost:8085/templates/BlogTemplate/search.html 
createPage: Processing pageId 403. Preview URL: 
http://localhost:8085/templates/BlogTemplate/authors.html 
All page creation calls complete.

Creating detail pages: 
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063051-developing-content-layout- for-content-and-experience-cloud
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063052-dynamic-dom- manipulation-in-content-layout 
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063045-getting-media-url-in- the-content-layout 
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063053-getting-reference- items-in-content-layout 
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063048-navigating-to-a- search-page-with-search-query 
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063050-alex-read 
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063047-jerrold-summers 
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063049-kelly-emerson 
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063043-samantha-howard 
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063046-raising-triggers-from- content-layout 
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063044-rendering-the-content- layout-using-mustache-template 
All detail page creation calls complete.

编译错误

编译过程中,您会得到三种类型的消息:信息、警告和错误。

  1. 信息消息是关于您应该注意的问题,但是这些消息可能应作为编译的一部分:
    • 将在运行时呈现的占位符内容项。
    • 缺少页布局编译器。页布局可能没有任何动态元素,因此如果缺少页布局,则不会被视为问题。
    • 标记为“访问时呈现”的项;即,站点开发人员希望在运行时动态呈现此组件,即使页已编译也是如此。
  2. 警告消息是关于可能会影响运行中站点性能的问题,应在可能的情况下进行修复。此类别中的项如下:
    • 缺少内容布局或定制组件编译器。如果没有这些项,组件将像以前那样动态地呈现到页中。
    • 缺少内容布局映射。您不太可能希望使用系统默认内容布局来呈现内容项。
  3. 错误消息是关于指示编译失败的问题。在可能的情况下,页将继续编译,但是整体编译将退出并显示错误。
    • 这很可能是由定制编译器中的 JavaScript 错误导致的,必须解决所有错误。

注:

为了减少重复消息,同一消息在每次编译中只出现一次,无论它是否出现在多个页上。

上述示例具有以下编译退出状态:

Compilation completed with 0 errors and 3 warnings. 
to display warnings, run with --verbose (-v) option.

如果使用 "-v" 选项重新运行编译步骤,将看到以下输出:

> cec compile-template BlogTemplate --verbose
Compile Template: compiling template BlogTemplate 
Oracle Content Management Site Compiler

createPage: Processing pageId 100. Preview URL: 
http://localhost:8085/templates/BlogTemplate/index.html 
createPage: Processing pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail.html
Info: no content item specified for placeholder: a890a65c-c0fc-451b-966b-e606ca18a1f4 
component will render at runtime. 
Info: no content item specified for placeholder: c90bbc10-c9d8-4a54-8dd4-7a8251e8efbb 
component will render at runtime. 
Info: no content item specified for placeholder: f12691e1-79ab-4d1f-a8b9-3af8c638dd26 
component will render at runtime.
createPage: Processing pageId 401. Preview URL: 
http://localhost:8085/templates/BlogTemplate/about.html 
createPage: Processing pageId 402. Preview URL: 
http://localhost:8085/templates/BlogTemplate/search.html
Info: Component: "fdfd0392-e901-48f6-8044-36803c836aa1" of type "scs-contentlist" marked as 
"render on access", will not be compiled. 
Info: Component: "ba9f3711-4367-444e-ae38-71289fc10e73" of type "scs-contentlist" marked as 
"render on access", will not be compiled. 
createPage: Processing pageId 403. Preview URL: 
http://localhost:8085/templates/BlogTemplate/authors.html 
All page creation calls complete. 

Creating detail pages: 
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063051-developing-content- layout-for-content-and-experience-cloud 
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063052-dynamic-dom- manipulation-in-content-layout 
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063045-getting-media-url-in- the-content-layout 
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063053-getting-reference- items-in-content-layout 
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063048-navigating-to-a- search-page-with-search-query 
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063050-alex-read 
Warning: failed to find content layout map entry for: Starter-Blog-Author:header. Will compile 
using the system default layout.
Warning: failed to find content layout map entry for: Starter-Blog-Author:content. Will compile 
using the system default layout. 
Warning: failed to find content layout map entry for: Starter-Blog-Author:sidebar. Will compile 
using the system default layout.  
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063047-jerrold-summers 
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063049-kelly-emerson 
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063043-samantha-howard 
createPage: Processing detail pageId 105. 
Preview URL: http://localhost:8085/templates/BlogTemplate/post-detail/1481786063046-raising-triggers-from- content-layout 
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063044-rendering-the-content- layout-using-mustache-template 
All detail page creation calls complete. 

Compilation completed with 0 errors and 3 warnings. 

*** compiled template is ready to test 
*** to render non-compiled pages, remove compiled files from under: /private/tmp/cec-
src/src/templates/BlogTemplate/static

详细信息页编译

详细信息页编译可整理它在编译过程中遇到的所有内容项。然后,它重新编译它找到的每个内容项的详细信息页,使用缩略名值定义新详细信息页的 URL。

前面的编译输出分为两个部分:

  1. 页编译
  2. 详细信息页编译

在前面的示例中,您将看到有关无 Starter-Blog-Author 页的内容布局映射条目的警告。但是,我们不需要 Starter-Blog-Author 的详细信息页。详细信息页仅针对 Starter-Blog-Post 内容项。要去除这些错误,如果内容项未在其设置中引用显式详细信息页,则可以使用以下选项从详细信息页编译中排除这些内容项:

--noDefaultDetailPageLink, -o  Do not generate compiled detail page for items/content lists
      that use the default detail page.

因此,在排除使用默认详细信息页的详细信息页创建的情况下,重新运行编译会生成以下输出:

> cec compile-template BlogTemplate --noDefaultDetailPageLink 
Compile Template: compiling template BlogTemplate 
Oracle Content Management Site Compiler 

createPage: Processing pageId 100. Preview URL: 
http://localhost:8085/templates/BlogTemplate/index.html 
createPage: Processing pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail.html 
createPage: Processing pageId 401. Preview URL: 
http://localhost:8085/templates/BlogTemplate/about.html 
createPage: Processing pageId 402. Preview URL: 
http://localhost:8085/templates/BlogTemplate/search.html 
createPage: Processing pageId 403. Preview URL: 
http://localhost:8085/templates/BlogTemplate/authors.html 
All page creation calls complete.

Creating detail pages: 
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063051-developing-content-
layout-for-content-and-experience-cloud
createPage: Processing detail pageId 105. Preview URL:
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063052-dynamic-dom -manipulation-in-content-layout
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063045-getting-media-url-in- the-content-layout
createPage: Processing detail pageId 105. Preview URL:  
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063053-getting-reference- items-in-content-layout
createPage: Processing detail pageId 105. Preview URL: 
http://localhost:8085/templates/BlogTemplate/post-detail/1481786063048-navigating-to-a- search-page-with-search-query
All detail page creation calls complete.

Compilation completed with no errors.

*** compiled template is ready to test 
*** to render non-compiled pages, remove compiled files from under: /private/tmp/cec-
src/src/templates/BlogTemplate/static

编译特定页

您不需要编译模板中的所有页,您可以选择要编译的页。如果您要调试或更新正在处理的特定页,而不必不断地重新编译整个站点,那么这将非常有用。

要编译特定页,请使用 --pages (-p) 选项,后跟要编译的页的列表。

注:

注:如果列表中页上的内容项引用了详细信息页,则也会编译详细信息页,即使它们未明确包含在内也是如此。

cec compile-template BlogTemplate --pages 401,402 
Compile Template: compiling template BlogTemplate 
Oracle Content Management Site Compiler

createPage: Processing pageId 401. Preview URL: 
http://localhost:8085/templates/BlogTemplate/about.html 
createPage: Processing pageId 402. Preview URL: 
http://localhost:8085/templates/BlogTemplate/search.html 
All page creation calls complete.

Compilation completed with no errors. 
*** compiled template is ready to test 
*** to render non-compiled pages, remove compiled files from under: /private/tmp/cec- 
src/src/templates/BlogTemplate/static