編譯您的樣板

編譯您的樣板時,系統會針對樣板內的網站,為每個 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