티스토리 뷰

SEO 및 소셜 미디어 용 태그는 동일한 정보를 공유하기 때문에 결합 될 수 있습니다.

내 umbraco 설치에서 웹 사이트 루트 노드, 페이지 노드 및 구성원 노드에 다음 속성을 추가했습니다.

최상위 노드에서 :

  • siteName-텍스트 상자
  • siteDescription-텍스트 영역
  • siteLocale-텍스트 상자 (예 : nb_NO)
  • facebookPageUrl- 텍스트 상자
  • facebookAppId-텍스트 상자
  • twitterUserName-텍스트 상자
  • siteLogo-미디어 선택기

페이지에서

  • pageTitle-텍스트 상자
  • pageSnippet-페이지 콘텐츠에 대한 160 자 텍스트 상자
  • 작성자-회원 선택기

회원

  • facebookProfilePage-텍스트 상자
  • twitterUserName-텍스트 상자
  • memberProfileUrl-텍스트 상자

그런 다음 다음 코드를 사용하여 모든 페이지에서 헤드 메타 태그를 렌더링합니다.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
    
    
            //  SITE INFORMATION 
                    string site_locale = "en_US";
                            if (Model.Content.AncestorOrSelf(1).HasProperty("siteLocale") && (Model.Content.GetPropertyValue<string>("siteLocale") != ""))
                                    { site_locale = Model.Content.GetPropertyValue<string>("siteLocale"); };
                                    
                                            // Check if root node has defined site name, otherwise use domain name.
                                                    string domain = System.Web.HttpContext.Current.Request.Url.Scheme + "://" + System.Web.HttpContext.Current.Request.Url.Authority;
                                                            string site_name = Model.Content.AncestorOrSelf(1).HasProperty("siteName") ? Model.Content.AncestorOrSelf(1).GetPropertyValue("siteName").ToString() : HttpContext.Current.Request.Url.Host.ToString();
                                                            
                                                                    // Check if site description exist, and default text if not.
                                                                            string site_description = Model.Content.AncestorOrSelf(1).HasProperty("siteDescription") ? Model.Content.AncestorOrSelf(1).GetPropertyValue("siteDescription").ToString() : "The website " + HttpContext.Current.Request.Url.Host.ToString();
                                                                                    string site_logo_url = "";
                                                                                            string site_logo_height = "";
                                                                                                    string site_logo_width = "";
                                                                                                    
                                                                                                            if (Model.Content.AncestorOrSelf(1).HasProperty("siteLogo") && (Model.Content.AncestorOrSelf(1).GetPropertyValue<int>("siteLogo") != 0))
                                                                                                                    {
                                                                                                                                var logo = Umbraco.TypedMedia(Model.Content.AncestorOrSelf(1).GetPropertyValue("siteLogo").ToString());
                                                                                                                                            site_logo_url = domain + logo.Url;
                                                                                                                                                        site_logo_height = logo.GetPropertyValue<string>("umbracoHeight");
                                                                                                                                                                    site_logo_width = logo.GetPropertyValue<string>("umbracoWidth");
                                                                                                                                                                            }
                                                                                                                                                                            
                                                                                                                                                                            
                                                                                                                                                                                    string site_fb_app_id = Model.Content.AncestorOrSelf(1).GetPropertyValue("facebookAppId").ToString();
                                                                                                                                                                                            string site_fb_page_url = Model.Content.AncestorOrSelf(1).GetPropertyValue("facebookPageUrl").ToString();
                                                                                                                                                                                                    string site_twitter_username = Model.Content.AncestorOrSelf(1).GetPropertyValue("twitterUserName").ToString();
                                                                                                                                                                                                    
                                                                                                                                                                                                            // PAGE INFORMATION 
                                                                                                                                                                                                                    // Use page title if defined, otherwise Model.Content.Name
                                                                                                                                                                                                                            string page_url = Model.Content.Url;
                                                                                                                                                                                                                                    string page_title = Model.Content.HasProperty("pageTitle") ? Model.Content.GetPropertyValue("pageTitle").ToString() : Model.Content.Name.ToString();
                                                                                                                                                                                                                                            DateTime page_created_date = Model.Content.CreateDate;
                                                                                                                                                                                                                                                    DateTime page_updated_date = Model.Content.UpdateDate;
                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                            string page_description = Model.Content.HasProperty("pageSnippet") ? Model.Content.GetPropertyValue("pageSnippet").ToString() : "";
                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                    // AUTHOR INFORMATION 
                                                                                                                                                                                                                                                                            // Check for information about the author of this page
                                                                                                                                                                                                                                                                                    bool hasAuthorInfo = false;
                                                                                                                                                                                                                                                                                            if (Model.Content.HasProperty("author") && (Model.Content.GetPropertyValue("author").ToString() != ""))
                                                                                                                                                                                                                                                                                                    {
                                                                                                                                                                                                                                                                                                                hasAuthorInfo = true;
                                                                                                                                                                                                                                                                                                                        }
                                                                                                                                                                                                                                                                                                                                string author_name = "";
                                                                                                                                                                                                                                                                                                                                        string author_facebook_page = "";
                                                                                                                                                                                                                                                                                                                                                string author_twitter_username = "";
                                                                                                                                                                                                                                                                                                                                                        string author_member_profile_url = "";
                                                                                                                                                                                                                                                                                                                                                                if (hasAuthorInfo)
                                                                                                                                                                                                                                                                                                                                                                        {
                                                                                                                                                                                                                                                                                                                                                                                    var author = Members.GetById((int)Model.Content.GetPropertyValue("author"));
                                                                                                                                                                                                                                                                                                                                                                                                author_name = author.Name;
                                                                                                                                                                                                                                                                                                                                                                                                            author_facebook_page = author.GetPropertyValue("facebookProfilePage").ToString();
                                                                                                                                                                                                                                                                                                                                                                                                                        author_twitter_username = author.GetPropertyValue("twitterUserName").ToString();
                                                                                                                                                                                                                                                                                                                                                                                                                                    author_member_profile_url = author.GetPropertyValue("memberProfileUrl").ToString();
                                                                                                                                                                                                                                                                                                                                                                                                                                            }
                                                                                                                                                                                                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                                                                                                                                                                                    // FEATURED IMAGE
                                                                                                                                                                                                                                                                                                                                                                                                                                                            // Check if there is a featured image for this page
                                                                                                                                                                                                                                                                                                                                                                                                                                                                    bool hasFeaturedImage = false;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                            string page_featuredimage_url = "";
                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    if (Model.Content.HasProperty("featuredImage") && (Model.Content.GetPropertyValue<int>("featuredImage") != 0))
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        hasFeaturedImage = true;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        if (hasFeaturedImage)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            var image = Umbraco.TypedMedia(Model.Content.GetPropertyValue("featuredImage").ToString());
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        page_featuredimage_url = domain + image.GetCropUrl("1200x630"); // Preferred size by Facebook
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <meta name="description" content="@page_description" />
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <meta property="og:title" content="@page_title" />
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <meta property="og:site_name" content="@site_name" />
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <meta property="og:url" content="@page_url" />
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <meta property="og:description" content="@page_description" />
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <meta property="og:image" content="@page_featuredimage_url" />
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <meta property="fb:app_id" content="@site_fb_app_id" />
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <meta property="og:type" content="article" />
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <meta property="og:locale" content="nb_NO" />
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <meta property="article:author" content="@author_facebook_page" />
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <meta property="article:publisher" content="@site_fb_page_url" />
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <meta name="twitter:title" content="@page_title" />
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <meta name="twitter:description" content="@page_description" />
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <meta name="twitter:image:src" content="@page_featuredimage_url" />
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <meta name="twitter:card" content="summary_large_image" />
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <meta name="twitter:site" content="@site_twitter_username" />
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <meta name="twitter:creator" content="@author_twitter_username" />
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <script type="application/ld+json">
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            "@@context": "http://schema.org",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    "@@type": "NewsArticle",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            "mainEntityOfPage":{
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    "@@type":"WebPage",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            "@@id":"@page_url"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    },
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            "headline": "@page_title",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    "image": {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            "@@type": "ImageObject",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    "url": "@page_featuredimage_url",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            "height": 630,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    "width": 1200
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            },
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    "datePublished": "@page_created_date.ToString("o")",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            "dateModified": "@page_updated_date.ToString("o")",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    "author": {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            "@@type": "Person",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    "name": "@author_name"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            },
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    "publisher": {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            "@@type": "Organization",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    "name": "@site_name",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            "logo": {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    "@@type": "ImageObject",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            "url": "@site_logo_url",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    "width": "@site_logo_width",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            "height": "@site_logo_height"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            },
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    "description": "@page_description"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                </script>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                


출처
https://stackoverflow.com/questions/39917251
댓글
공지사항
Total
Today
Yesterday
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30