現代化網站品牌和風格

Justin-Liu發表於2018-05-28

部落格地址:http://blog.csdn.net/FoxDave
SharePoint現代化使用者介面處理品牌風格的方式跟經典SharePoint不同;特別地,它忽略了自定義母版頁或外部CSS配置,這些在現代化網站並不可用。我們可以選擇繼續保留這些內容,它們仍然能夠對經典的使用者介面頁面起作用,但是切換回預設母版頁並移除外部樣式顯然是更乾淨整潔的方式。
除了自定義母版頁和外部樣式設定之外,我們可能還使用了經典的自定義主題。這些經典的自定義主題在現代化使用者介面下仍然能工作,但是面向未來更好的方式是新的租戶控制的SharePoint主題,同樣也能在新舊兩種模式下工作。

檢測使用了自定義母版頁和外部樣式的網站

進行檢測推薦使用之前介紹的掃描工具:SharePoint “Modern” user interface experience scanner。它會在我們的租戶範圍內對所有網站進行深度的分析,建立相應的報告告知我們關於不相容母版頁和外部樣式的具體細節,我們可以基於報告去修復這些網站。

復原到預設設定
下面是PnP(Patterns and Practices)的PowerShell指令碼用來複原到預設設定:

$minimumVersion = New-Object System.Version("2.24.1803.0")
if (-not (Get-InstalledModule -Name SharePointPnPPowerShellOnline -MinimumVersion $minimumVersion -ErrorAction Ignore))
{
    Install-Module SharePointPnPPowerShellOnline -MinimumVersion $minimumVersion -Scope CurrentUser
}
Import-Module SharePointPnPPowerShellOnline -DisableNameChecking -MinimumVersion $minimumVersion

Connect-PnPOnline -Url "<your site url>"

# Set out-of-the-box master page
Set-PnPMasterPage -MasterPageSiteRelativeUrl _catalogs/masterpage/seattle.master -CustomMasterPageSiteRelativeUrl _catalogs/masterpage/seattle.master

# Remove the alternate CSS setting
$web = Get-PnPWeb -Includes AlternateCssUrl
$web.AlternateCssUrl = ""
$web.Context.ExecuteQuery()

使用租戶控制的SharePoint主題

SharePoint提供了一些列拆箱即用的預設主題供我們使用,但是如果我們想要推廣我們的公司品牌,我們應該建立自己的公司主題並隱藏預設的主題。配置完成後,使用者只能從我們配置的主題中進行選擇,我們可以通過程式設計的方式將這種主題設定作為網站現代化的一部分。

新增一個SharePoint公司主題
下面是PnP的PowerShell指令碼用來演示如何新增一個SharePoint公司主題:

$minimumVersion = New-Object System.Version("2.24.1803.0")
if (-not (Get-InstalledModule -Name SharePointPnPPowerShellOnline -MinimumVersion $minimumVersion -ErrorAction Ignore))
{
    Install-Module SharePointPnPPowerShellOnline -MinimumVersion $minimumVersion -Scope CurrentUser
}
Import-Module SharePointPnPPowerShellOnline -DisableNameChecking -MinimumVersion $minimumVersion

Connect-PnPOnline -Url "<your tenant admin url>"

# Define your company theme colors
$themepalette = @{
      "themePrimary" = "#00ffff";
      "themeLighterAlt" = "#f3fcfc";
      "themeLighter" = "#daffff";
      "themeLight" = "#affefe";
      "themeTertiary" = "#76ffff";
      "themeSecondary" = "#39ffff";
      "themeDarkAlt" = "#00c4c4";
      "themeDark" = "#009090";
      "themeDarker" = "#005252";
      "neutralLighterAlt" = "#f8f8f8";
      "neutralLighter" = "#f4f4f4";
      "neutralLight" = "#eaeaea";
      "neutralQuaternaryAlt" = "#dadada";
      "neutralQuaternary" = "#d0d0d0";
      "neutralTertiaryAlt" = "#c8c8c8";
      "neutralTertiary" = "#a6a6a6";
      "neutralSecondaryAlt" = "#767676";
      "neutralSecondary" = "#666666";
      "neutralPrimary" = "#333";
      "neutralPrimaryAlt" = "#3c3c3c";
      "neutralDark" = "#212121";
      "black" = "#000000";
      "white" = "#fff";
      "primaryBackground" = "#fff";
      "primaryText" = "#333"
     }

# Add the company theme
Add-PnPTenantTheme -Identity "CustomCompanyTheme" -Palette $themepalette -IsInverted:$false

使用我們的SharePoint公司主題
我們可以通過下面的指令碼來設定使用我們的公司主題:

$minimumVersion = New-Object System.Version("2.24.1803.0")
if (-not (Get-InstalledModule -Name SharePointPnPPowerShellOnline -MinimumVersion $minimumVersion -ErrorAction Ignore))
{
    Install-Module SharePointPnPPowerShellOnline -MinimumVersion $minimumVersion -Scope CurrentUser
}
Import-Module SharePointPnPPowerShellOnline -DisableNameChecking -MinimumVersion $minimumVersion

Connect-PnPOnline -Url "<your site url>"

# Set the company theme
Set-PnPWebTheme -Theme "CustomCompanyTheme"

相關文章