mirror of
https://github.com/wahyd4/libr-ios.git
synced 2026-08-09 05:06:46 +10:00
142 lines
4.3 KiB
Swift
142 lines
4.3 KiB
Swift
//
|
|
// Post.swift
|
|
// librx
|
|
//
|
|
// Created by Yunlong Zheng on 15/8/15.
|
|
// Copyright (c) 2015年 librx. All rights reserved.
|
|
//
|
|
|
|
class Post: Replyable {
|
|
|
|
private let titleMaxLength:Int = 35
|
|
|
|
let id: Int
|
|
let viewedTimes: Int
|
|
var title: String
|
|
let description: String
|
|
let createdAt: String
|
|
let type: String
|
|
let url: String
|
|
let thumbnail: String
|
|
let likeCount: Int
|
|
let liked: Bool
|
|
let goodFormat: Bool
|
|
let content: String
|
|
let summary: String
|
|
let firstSharer:FirstSharer
|
|
let processed: Bool
|
|
let bookmarked: Bool
|
|
|
|
init(
|
|
id: Int = 0,
|
|
goodFormat: Bool = false,
|
|
content: String = "",
|
|
viewedTimes: Int = 0,
|
|
title: String = "",
|
|
description: String = "",
|
|
createdAt: String = "",
|
|
type: String = "page",
|
|
url: String = "",
|
|
thumbnail: String = "",
|
|
likeCount: Int = 0,
|
|
summary: String = "",
|
|
processed: Bool = true,
|
|
liked: Bool = false,
|
|
bookmarked: Bool = false,
|
|
firstSharer:FirstSharer = FirstSharer.defaultShare()
|
|
){
|
|
self.id = id
|
|
self.goodFormat = goodFormat
|
|
self.content = content
|
|
self.viewedTimes = viewedTimes
|
|
self.createdAt = createdAt
|
|
self.type = type
|
|
self.url = url
|
|
self.thumbnail = thumbnail
|
|
self.likeCount = likeCount
|
|
self.title = title
|
|
self.description = description
|
|
self.firstSharer = firstSharer
|
|
self.summary = summary
|
|
self.processed = processed
|
|
self.liked = liked
|
|
self.bookmarked = bookmarked
|
|
}
|
|
|
|
func getformatPostTitle() -> String {
|
|
|
|
let title:String = self.title.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
|
|
|
|
if title.characters.count > titleMaxLength {
|
|
return title.substringWithRange(Range<String.Index>(start: title.startIndex.advancedBy(0), end: title.endIndex.advancedBy(-10))) + "..."
|
|
}
|
|
|
|
return title
|
|
|
|
}
|
|
|
|
func getFormatCreateDateTime() -> String {
|
|
return DateUtil.format(self.createdAt)
|
|
}
|
|
|
|
func getFormatContent() -> String {
|
|
let content: String = "<html><head>"
|
|
+ "<meta name='viewport' content='width=device-width, initial-scale=1'>"
|
|
+ "<link rel='stylesheet' href='//cdn.jsdelivr.net/highlight.js/8.8.0/styles/solarized_light.min.css'>"
|
|
+ "<link href='http://7xlrny.com1.z0.glb.clouddn.com/published_post.css' rel='stylesheet'>"
|
|
+ "<style>header.intro-header{ background-image:none;background-color: #3FB5A3; }</style>"
|
|
+ "</head>"
|
|
+ "<body>"
|
|
+ "<header class='intro-header'>"
|
|
+ "<div class='container'>"
|
|
+ "<div class='row'>"
|
|
+ "<div class='col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1'>"
|
|
+ "<div class='post-heading'><h2>\(self.title)</h2></div></div></div>"
|
|
+ "</div>"
|
|
+ "</header>"
|
|
+ "<article><div class='container'>"
|
|
+ "<div class='row'>"
|
|
+ "<div class='col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1 post'>"
|
|
+ "\(self.content)"
|
|
+ "</div></div></div></article>"
|
|
+ "<script src='https://cdn.jsdelivr.net/jquery/2.0.0/jquery.min.js'></script>"
|
|
+ "<script src='//cdn.jsdelivr.net/highlight.js/8.8.0/highlight.min.js'></script>"
|
|
+ "<script>(function() {$(function() {return $('pre').each(function(i, block) {"
|
|
+ "return hljs.highlightBlock(block);});});}).call(this);</script>"
|
|
+ "</body></html>"
|
|
return content
|
|
}
|
|
|
|
func to_string()-> String {
|
|
|
|
return "Post{'id':\(self.id), 'title': \(self.title), 'likeed': \(self.liked), 'bookmarked': \(self.bookmarked)}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class FirstSharer {
|
|
|
|
let id:Int
|
|
let name: String
|
|
let avatar: String
|
|
|
|
init(id:Int,
|
|
name: String,
|
|
avatar: String = ""){
|
|
|
|
self.id = id
|
|
self.name = name
|
|
self.avatar = avatar
|
|
|
|
}
|
|
|
|
static func defaultShare() -> FirstSharer {
|
|
|
|
return FirstSharer(id: 0, name: "unkown", avatar: "")
|
|
|
|
}
|
|
|
|
}
|
|
|