use of org.b3log.solo.model.sitemap.URL in project solo by b3log.
the class SitemapProcessor method addNavigations.
/**
* Adds navigations into the specified sitemap.
*
* @param sitemap the specified sitemap
* @throws Exception exception
*/
private void addNavigations(final Sitemap sitemap) throws Exception {
final JSONObject result = pageRepository.get(new Query());
final JSONArray pages = result.getJSONArray(Keys.RESULTS);
for (int i = 0; i < pages.length(); i++) {
final JSONObject page = pages.getJSONObject(i);
final String permalink = page.getString(Page.PAGE_PERMALINK);
final URL url = new URL();
// Just filters for user mistakes tolerance
if (!permalink.contains("://")) {
url.setLoc(Latkes.getServePath() + permalink);
} else {
url.setLoc(permalink);
}
sitemap.addURL(url);
}
}
use of org.b3log.solo.model.sitemap.URL in project solo by b3log.
the class SitemapProcessor method addArticles.
/**
* Adds articles into the specified sitemap.
*
* @param sitemap the specified sitemap
* @throws Exception exception
*/
private void addArticles(final Sitemap sitemap) throws Exception {
// XXX: query all articles?
final Query query = new Query().setCurrentPageNum(1).setFilter(new PropertyFilter(Article.ARTICLE_IS_PUBLISHED, FilterOperator.EQUAL, true)).addSort(Article.ARTICLE_CREATE_DATE, SortDirection.DESCENDING);
// XXX: maybe out of memory
final JSONObject articleResult = articleRepository.get(query);
final JSONArray articles = articleResult.getJSONArray(Keys.RESULTS);
for (int i = 0; i < articles.length(); i++) {
final JSONObject article = articles.getJSONObject(i);
final String permalink = article.getString(Article.ARTICLE_PERMALINK);
final URL url = new URL();
url.setLoc(Latkes.getServePath() + permalink);
final Date updateDate = (Date) article.get(Article.ARTICLE_UPDATE_DATE);
final String lastMod = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(updateDate);
url.setLastMod(lastMod);
sitemap.addURL(url);
}
}
use of org.b3log.solo.model.sitemap.URL in project solo by b3log.
the class SitemapProcessor method addArchives.
/**
* Adds archives (archive-articles) into the specified sitemap.
*
* @param sitemap the specified sitemap
* @throws Exception exception
*/
private void addArchives(final Sitemap sitemap) throws Exception {
final JSONObject result = archiveDateRepository.get(new Query());
final JSONArray archiveDates = result.getJSONArray(Keys.RESULTS);
for (int i = 0; i < archiveDates.length(); i++) {
final JSONObject archiveDate = archiveDates.getJSONObject(i);
final long time = archiveDate.getLong(ArchiveDate.ARCHIVE_TIME);
final String dateString = DateFormatUtils.format(time, "yyyy/MM");
final URL url = new URL();
url.setLoc(Latkes.getServePath() + "/archives/" + dateString);
sitemap.addURL(url);
}
}
use of org.b3log.solo.model.sitemap.URL in project solo by b3log.
the class SitemapProcessor method addTags.
/**
* Adds tags (tag-articles) and tags wall (/tags.html) into the specified sitemap.
*
* @param sitemap the specified sitemap
* @throws Exception exception
*/
private void addTags(final Sitemap sitemap) throws Exception {
final JSONObject result = tagRepository.get(new Query());
final JSONArray tags = result.getJSONArray(Keys.RESULTS);
for (int i = 0; i < tags.length(); i++) {
final JSONObject tag = tags.getJSONObject(i);
final String link = URLEncoder.encode(tag.getString(Tag.TAG_TITLE), "UTF-8");
final URL url = new URL();
url.setLoc(Latkes.getServePath() + "/tags/" + link);
sitemap.addURL(url);
}
// Tags wall
final URL url = new URL();
url.setLoc(Latkes.getServePath() + "/tags.html");
sitemap.addURL(url);
}
Aggregations