-
Notifications
You must be signed in to change notification settings - Fork 17
/
ArticlePage.cs
68 lines (58 loc) · 3.04 KB
/
ArticlePage.cs
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
namespace DemoSite.Models.Pages {
using KalikoCMS.Attributes;
using KalikoCMS.Core;
using KalikoCMS.PropertyType;
using KalikoCMS.Search;
/// <summary>
/// This is a standard page type for articles. We got a few defined properties.
/// </summary>
[PageType("ArticlePage", "Article page", PageTypeDescription = "Used for articles", PreviewImage = "/Assets/Images/articlepage.png")]
public class ArticlePage : CmsPage, IIndexable {
/// <summary>
/// Simple string headline to use instead of pagename in the articles.
/// </summary>
[Property("Headline")]
public virtual StringProperty Headline { get; set; }
/// <summary>
/// To set a required width and/or height for images use the [ImageProperty]
/// attribute instead of the standard [Property]
/// </summary>
[ImageProperty("Top image", Width = 848, Height = 180)]
public virtual ImageProperty TopImage { get; set; }
[Property("Preamble")]
public virtual TextProperty Preamble { get; set; }
[Property("Main body")]
public virtual HtmlProperty MainBody { get; set; }
/// <summary>
/// The tag property enable tags for a particular page type. Notice that you can
/// use multiple tag spaces for the same page by setting different tag contexts.
/// Be sure to use [TagProperty] to define the TagContext, otherwise it will
/// fallback to the standard tag space.
/// </summary>
[TagProperty("Tags", TagContext = "article")]
public virtual TagProperty Tags { get; set; }
/// <summary>
/// This function is required when implementing IIndexable and will feed the
/// search engine with the content that should be indexed when a page of this
/// particular page type is saved.
/// You should always get the IndexItem object by calling GetBaseIndexItem and
/// add the content you wish to be indexed for search.
/// </summary>
/// <param name="page">The page that was saved</param>
/// <returns>An object containing the content to be indexed</returns>
public IndexItem MakeIndexItem(CmsPage page) {
// We start by casting the generic CmsPage object to our page type
var typedPage = page.ConvertToTypedPage<ArticlePage>();
// Get the base index item with basic information already set
var indexItem = typedPage.GetBaseIndexItem();
// Add additional information to index, this is where you add the page's properties that should be searchable
indexItem.Title = typedPage.Headline.Value;
indexItem.Summary = typedPage.Preamble.Value;
indexItem.Content = typedPage.Preamble.Value + " " + typedPage.MainBody.Value;
indexItem.Tags = typedPage.Tags.ToString();
// We set a category in order to be able to single out search hits
indexItem.Category = "Article";
return indexItem;
}
}
}