<commit_before>/// <reference path="../../../typings/angularjs/angular.d.ts" />
/// <reference path="../../app.common.ts" />

module Blog.Service {
	
	/**
	 * The service that provides data to controllers.
	 */
	export class ContentService {
		
		private metaArticles: Common.MetaArticle[] = null;
		
		private metaCache: angular.ICacheObject;
		
		private cache: angular.ICacheObject;
		
		/**
		 * Used as dependecy-injected factory.
		 */
		public static inlineAnnotatedConstructor: any[] = ['$http', '$q', '$cacheFactory', '$sce', ContentService];
		
		public constructor(private $http: angular.IHttpService, private $q: angular.IQService, private $cacheFactoryService: angular.ICacheFactoryService, private $sce: angular.ISCEService) {
			this.metaCache = $cacheFactoryService('contentMeta');
			this.cache = $cacheFactoryService('content');
		};
		
		/**
		 * Used to initialize the meta-content. That means it will load
		 * the content.json which gives us information about all the
		 * available content.
		 */
		public initializeMetaContent(): angular.IPromise<Common.MetaArticle[]> {
			return this.$http.get<Common.MetaArticle[]>('content/content.json').then(metaArts => {
				if (this.metaArticles !== null) {
					return this.$q.when(this.metaArticles.slice(0));
				}

				this.metaArticles = metaArts.data;
				
				for (let i = 0; i < metaArts.data.length; i++) {
					this.metaCache.put(metaArts.data[i].urlName, metaArts.data[i]);
				}
				
				return metaArts.data;
			});
		};
		
		/**
		 * Gets one Article by its URL-name. Uses caching internally.
		 */
		public articleByUrlName(urlName: string): angular.IPromise<Common.Article> {
			var article = this.cache.get<Common.Article>(urlName);
			
			return article === undefined ? this.getMetaArticles().then(metaArts => {
				return this.$http.get<string>(this.metaCache.get<Common.MetaArticle>(urlName).path).then(arg => {
					var article = new Common.Article(
						this.metaCache.get<Common.MetaArticle>(urlName), arg.data, this.$sce);

					this.cache.put(urlName, article);
					return article;
				});
			}) : this.$q.when(article);
		};
		
		/**
		 * This function returns all MetaArticles. The optional argument filter allows
		 * to return a filtered subset of all articles.
		 * 
		 * @param filter if the filter is a 2Tuple, then its t1 is used for specifying
		 *  the meta tag to compare with and its t2 is used for the comparison. So if
		 *  you were to provide <"displayat", "topnav"> then only those articles which
		 *  have the meta-tag "displayat" with the value "topnav" would be returned.
		 *  If the provided filter is a function, then it will be given each MetaArticle
		 *  and must return true or false.
		 */
		public getMetaArticles(filter?: Common.I2Tuple<string, string>|((metaArticle:Common.MetaArticle) => boolean)): angular.IPromise<Common.MetaArticle[]> {
			
			var postFilter = filter instanceof Common.I2Tuple ?
				(metaArt: Common.MetaArticle) => metaArt.hasOwnProperty(filter.t1) && metaArt[filter.t1] === filter.t2 :
				(filter instanceof Function ? filter : (dummy: Common.MetaArticle) => true);
			
			return this.metaArticles === null ? this.initializeMetaContent().then(() => {
				return this.metaArticles.slice(0).filter(postFilter);
			}) : this.$q.when(this.metaArticles.slice(0).filter(postFilter));
		}
	};<commit_msg>Tiny refactorings to the content-service to format dates consistently<commit_after>/// <reference path="../../../typings/angularjs/angular.d.ts" />
/// <reference path="../../app.common.ts" />

module Blog.Service {
	
	/**
	 * The service that provides data to controllers.
	 */
	export class ContentService {
		
		private metaArticles: Common.MetaArticle[] = null;
		
		private metaCache: angular.ICacheObject;
		
		private cache: angular.ICacheObject;
		
		/**
		 * Used as dependecy-injected factory.
		 */
		public static inlineAnnotatedConstructor: any[] = ['$http', '$q', '$cacheFactory', '$sce', ContentService];
		
		public constructor(private $http: angular.IHttpService, private $q: angular.IQService, private $cacheFactoryService: angular.ICacheFactoryService, private $sce: angular.ISCEService) {
			this.metaCache = $cacheFactoryService('contentMeta');
			this.cache = $cacheFactoryService('content');
		};
		
		/**
		 * Used to initialize the meta-content. That means it will load
		 * the content.json which gives us information about all the
		 * available content.
		 */
		public initializeMetaContent(): angular.IPromise<Common.MetaArticle[]> {
			return this.$http.get<Common.MetaArticle[]>('content/content.json').then(metaArts => {
				if (this.metaArticles !== null) {
					return this.$q.when(this.metaArticles.slice(0));
				}

				this.metaArticles = metaArts.data;
				
				for (let i = 0; i < metaArts.data.length; i++) {
					this.metaCache.put(metaArts.data[i].urlName, metaArts.data[i]);
				}
				
				return metaArts.data;
			});
		};
		
		/**
		 * Gets one Article by its URL-name. Uses caching internally.
		 */
		public articleByUrlName(urlName: string): angular.IPromise<Common.Article> {
			var article = this.cache.get<Common.Article>(urlName);
			
			return article === undefined ? this.getMetaArticles().then(metaArts => {
				return this.$http.get<string>(this.metaCache.get<Common.MetaArticle>(urlName).path).then(arg => {
					var article = new Common.Article(
						this.metaCache.get<Common.MetaArticle>(urlName), arg.data, this.$sce);

					this.cache.put(urlName, article);
					return article;
				});
			}) : this.$q.when(article);
		};
		
		/**
		 * This function returns all MetaArticles. The optional argument filter allows
		 * to return a filtered subset of all articles.
		 * 
		 * @param filter if the filter is a 2Tuple, then its t1 is used for specifying
		 *  the meta tag to compare with and its t2 is used for the comparison. So if
		 *  you were to provide <"displayat", "topnav"> then only those articles which
		 *  have the meta-tag "displayat" with the value "topnav" would be returned.
		 *  If the provided filter is a function, then it will be given each MetaArticle
		 *  and must return true or false.
		 */
		public getMetaArticles(filter?: Common.I2Tuple<string, string>|((metaArticle:Common.MetaArticle) => boolean)): angular.IPromise<Common.MetaArticle[]> {
			
			var postFilter = filter instanceof Common.I2Tuple ?
				(metaArt: Common.MetaArticle) => metaArt.hasOwnProperty(filter.t1) && metaArt[filter.t1] === filter.t2 :
				(filter instanceof Function ? filter : (dummy: Common.MetaArticle) => true);
			var dateMethod = Date.prototype['toGMTString'] || Date.prototype.toLocaleString || Date.prototype.toString;
			
			return this.metaArticles === null ? this.initializeMetaContent().then(() => {
				return this.metaArticles.slice(0).filter(postFilter).map(metaArt => {
					metaArt.lastMod = dateMethod.call(new Date(Date.parse(metaArt.lastMod)));
					return metaArt;
				});
			}) : this.$q.when(this.metaArticles.slice(0).filter(postFilter));
		}
	};
{'fraction_non_alphanumeric': 0.1363701475433319, 'fraction_numerical': 0.0034379028792436614, 'mean_word_length': 3.6422872340425534, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '236955', 'n_tokens_mistral': 2430, 'n_tokens_neox': 2024, 'n_words': 530}