Issue #6 List of pages per user

This commit is contained in:
Alexis Hassler 2019-05-18 11:21:16 +02:00
parent 45bc42f572
commit e285abc65b
21 changed files with 109 additions and 116 deletions

View File

@ -3,12 +3,11 @@ layout: default
title: All pages title: All pages
menu: ['global'] menu: ['global']
--- ---
{%- include /functions/wiki-pages.html -%}
<ul class="columns"> <ul class="columns">
{%- for page in wiki_pages -%} {%- for page in site.data.wiki_pages -%}
<li> <li>
<a href="{{ page.url }}.html">{{ page.title }}</a>&nbsp; [{{ page.bytes }} bytes] <a href="{{ page.url }}.html">{{ page.title }}</a>&nbsp; [{{ page.bytes }} bytes]
{%- if page.author -%}&nbsp;(by <a href="/{{ site.data.i18n[site.lang].prefix.user }}{{ page.author }}.html">{{ page.author }}</a>) {%- endif -%} {%- if page.author_full -%}&nbsp;(by <a href="{{ page.author_full.url }}.html">{{ page.author_full.name }}</a>) {%- endif -%}
</li> </li>
{%- endfor -%} {%- endfor -%}
</ul> </ul>

View File

@ -3,11 +3,10 @@ layout: default
title: Tags title: Tags
menu: ['global'] menu: ['global']
--- ---
{%- include /functions/wiki-tags.html -%}
<ul> <ul>
{%- for tag in tags -%} {%- for tag in site.data.wiki_tags -%}
{%- assign counter = 0 -%} {%- assign counter = 0 -%}
{%- for other_page in wiki_pages %} {%- for other_page in site.data.wiki_pages %}
{%- if other_page.tags contains tag -%} {%- if other_page.tags contains tag -%}
{%- assign counter = counter | plus: 1 -%} {%- assign counter = counter | plus: 1 -%}
{%- endif -%} {%- endif -%}

View File

@ -3,14 +3,13 @@ layout: default
title: Redirects title: Redirects
menu: ['global'] menu: ['global']
--- ---
{%- include /functions/wiki-pages.html -%}
{%- assign redirect_pages = site.special | where_exp: 'page', 'page.redirect' -%} {%- assign redirect_pages = site.special | where_exp: 'page', 'page.redirect' -%}
<ul> <ul>
{%- for source_page in redirect_pages -%} {%- for source_page in redirect_pages -%}
<li> <li>
{%- assign redirect = source_page.redirect | liquify | prepend: '/' -%} {%- assign redirect = source_page.redirect | liquify | prepend: '/' -%}
{%- for other_page in wiki_pages -%} {%- for other_page in site.data.wiki_pages -%}
{%- if other_page.id == redirect -%} {%- if other_page.id == redirect -%}
{%- assign redirect_page = other_page -%} {%- assign redirect_page = other_page -%}
{%- endif -%} {%- endif -%}

View File

@ -3,15 +3,10 @@ layout: default
title: Users title: Users
menu: ['global'] menu: ['global']
--- ---
{%- include /functions/wiki-tags.html -%}
<ul> <ul>
{%- for user in site.data.users -%} {%- for author in site.data.authors -%}
{%- assign counter = 0 -%} <li>
{%- for other_page in wiki_pages %} <a href="{{ author.url }}.html">{{ author.name }}</a> (<a href="{{ author.contributions_url }}.html">{{author.contributions_count}} pages</a>)
{%- if other_page.author == user[0] -%} </li>
{%- assign counter = counter | plus: 1 -%}
{%- endif -%}
{%- endfor -%} {%- endfor -%}
<li><a href="/{{ site.data.i18n[site.lang].prefix.user }}{{ user[0] }}.html">{{ user[1].name }}</a> ({{counter}} pages)</li>
{%- endfor -%}
</ul> </ul>

View File

@ -3,8 +3,7 @@ layout: default
title: Long pages title: Long pages
menu: ['global'] menu: ['global']
--- ---
{%- include /functions/wiki-pages.html -%} {%- assign long_pages = site.data.wiki_pages | sort: 'bytes' | reverse -%}
{%- assign long_pages = wiki_pages | sort: 'bytes' | reverse -%}
<ol> <ol>
{%- for page in long_pages limit:50 -%} {%- for page in long_pages limit:50 -%}
<li> <li>

View File

@ -3,8 +3,7 @@ layout: default
title: Recent changes title: Recent changes
menu: ['global'] menu: ['global']
--- ---
{%- include /functions/wiki-pages.html -%} {%- assign recent_changes = site.data.wiki_pages | where_exp: 'page', 'page.modified' | sort: 'modified' | reverse -%}
{%- assign recent_changes = wiki_pages | where_exp: 'page', 'page.modified' | sort: 'modified' | reverse -%}
<ul> <ul>
{%- for page in recent_changes limit:20 -%} {%- for page in recent_changes limit:20 -%}
<li> <li>

View File

@ -3,8 +3,7 @@ layout: default
title: Short pages title: Short pages
menu: ['global'] menu: ['global']
--- ---
{%- include /functions/wiki-pages.html -%} {%- assign long_pages = site.data.wiki_pages | sort: 'bytes' -%}
{%- assign long_pages = wiki_pages | sort: 'bytes' -%}
<ol> <ol>
{%- for page in long_pages limit:50 -%} {%- for page in long_pages limit:50 -%}
<li> <li>

View File

@ -7,8 +7,7 @@ layout: null
<title>{{ site.title }}</title> <title>{{ site.title }}</title>
<description>{{ site.description }}</description> <description>{{ site.description }}</description>
<link>{{ site.url }}</link> <link>{{ site.url }}</link>
{% include /functions/wiki-pages.html %} {% for post in site.data.wiki_pages reversed%}
{% for post in wiki_pages reversed%}
{% unless post.draft %} {% unless post.draft %}
<item> <item>
<title>{{ post.title | xml_escape }}</title> <title>{{ post.title | xml_escape }}</title>

View File

@ -2,46 +2,11 @@
layout: default layout: default
title: Tags title: Tags
--- ---
{% assign var = 10 %}
{% comment %}
=======================
The following part extracts all the tags from your posts and sort tags, so that you do not need to manually collect your tags to a place.
=======================
{% endcomment %}
{% assign rawtags = "" %}
{% include /functions/wiki-pages.html %}
{% for wiki_page in wiki_pages %}
{% assign ttags = wiki_page.tags | join:'|' | append:'|' %}
{% assign rawtags = rawtags | append:ttags %}
{% endfor %}
{% assign rawtags = rawtags | split:'|' | sort %}
{% comment %}
=======================
The following part removes dulpicated tags and invalid tags like blank tag.
=======================
{% endcomment %}
{% assign tags = "" %}
{% for tag in rawtags %}
{% if tag != "" %}
{% if tags == "" %}
{% assign tags = tag | split:'|' %}
{% endif %}
{% unless tags contains tag %}
{% assign tags = tags | join:'|' | append:'|' | append:tag | split:'|' %}
{% endunless %}
{% endif %}
{% endfor %}
<ul> <ul>
{% for tag in tags %} {% for tag in site.data.wiki_tags %}
<li id="n-tag-{{ tag }}"><a href="/{{ site.data.i18n[site.lang].prefix.tag }}{{ tag }}.html">{{ tag }}</a></li> <li id="n-tag-{{ tag }}"><a href="/{{ site.data.i18n[site.lang].prefix.tag }}{{ tag }}.html">{{ tag }}</a></li>
<ul> <ul>
{% for other_page in wiki_pages %} {% for other_page in site.data.wiki_pages %}
{% if other_page.tags contains tag %} {% if other_page.tags contains tag %}
<li><a href="{{ other_page.url }}">{{ other_page.title }}</a></li> <li><a href="{{ other_page.url }}">{{ other_page.title }}</a></li>
{% endif %} {% endif %}

View File

@ -1,5 +1,3 @@
{%- include /functions/wiki-pages.html -%}
{%- if include.page -%} {%- if include.page -%}
{%- assign source_page = include.source_page -%} {%- assign source_page = include.source_page -%}
{%- else -%} {%- else -%}
@ -7,7 +5,7 @@
{%- endif -%} {%- endif -%}
{%- assign redirect = source_page.redirect | liquify -%} {%- assign redirect = source_page.redirect | liquify -%}
{%- for other_page in wiki_pages -%} {%- for other_page in site.data.wiki_pages -%}
{%- if other_page.id == redirect -%} {%- if other_page.id == redirect -%}
{%- assign redirect_page = other_page -%} {%- assign redirect_page = other_page -%}
{%- endif -%} {%- endif -%}

View File

@ -1,7 +0,0 @@
{%- assign wiki_pages = '' | split: '' -%}
{%- for collection in site.collections -%}
{%- assign prefix = collection.label | slice: 0, 4 -%}
{%- if prefix == 'wiki' -%}
{%- assign wiki_pages = wiki_pages | concat: collection.docs -%}
{%- endif -%}
{%- endfor -%}

View File

@ -1,33 +0,0 @@
{%- comment -%}
=======================
The following part extracts all the tags from your posts and sort tags, so that you do not need to manually collect your tags to a place.
=======================
{%- endcomment -%}
{%- assign rawtags = "" -%}
{%- include /functions/wiki-pages.html -%}
{%- for wiki_page in wiki_pages -%}
{%- assign ttags = wiki_page.tags | join:'|' | append:'|' -%}
{%- assign rawtags = rawtags | append:ttags -%}
{%- endfor -%}
{%- assign rawtags = rawtags | split:'|' | sort -%}
{%- comment -%}
=======================
The following part removes dulpicated tags and invalid tags like blank tag.
=======================
{%- endcomment -%}
{%- assign tags = "" -%}
{%- for tag in rawtags -%}
{%- if tag != "" -%}
{%- if tags == "" -%}
{%- assign tags = tag | split:'|' -%}
{%- endif -%}
{%- unless tags contains tag -%}
{%- assign tags = tags | join:'|' | append:'|' | append:tag | split:'|' -%}
{%- endunless -%}
{%- endif -%}
{%- endfor -%}
{%- assign wiki_tags = tags -%}

View File

@ -3,11 +3,10 @@
<h3>{{ site.data.i18n[site.lang].label.tags }}</h3> <h3>{{ site.data.i18n[site.lang].label.tags }}</h3>
<div class="portlet-body"> <div class="portlet-body">
<ul> <ul>
{%- include /functions/wiki-pages.html -%}
{%- for tag in page.tags -%} {%- for tag in page.tags -%}
<li id="n-tag-{{ tag }}"><a href="/{{ site.data.i18n[site.lang].prefix.tag }}{{ tag }}.html">{{ tag }}</a></li> <li id="n-tag-{{ tag }}"><a href="/{{ site.data.i18n[site.lang].prefix.tag }}{{ tag }}.html">{{ tag }}</a></li>
<ul> <ul>
{%- for other_page in wiki_pages -%} {%- for other_page in site.data.wiki_pages -%}
{%- if other_page.tags contains tag and other_page.id != page.id -%} {%- if other_page.tags contains tag and other_page.id != page.id -%}
<li><a href="{{ other_page.url }}.html">{{ other_page.title }}</a></li> <li><a href="{{ other_page.url }}.html">{{ other_page.title }}</a></li>
{%- endif -%} {%- endif -%}

View File

@ -1,9 +1,9 @@
{%- if page.author -%} {%- if page.author_full -%}
<div id="author" class="portlet"> <div id="author" class="portlet">
<div class="portlet-body"> <div class="portlet-body">
{%- assign author = site.data.users[page.author] -%} {%- assign author = page.author_full -%}
<ul> <ul>
<li><a href="/{{ site.data.i18n[site.lang].prefix.user }}{{ page.author }}">{{ author.name }}</a></li> <li><a href="{{ author.url }}">{{ author.name }}</a></li>
</ul> </ul>
{%- if author.logo -%} {%- if author.logo -%}
<img src="/{{ author.logo }}" style="max-width: 100%;margin: 3px" /> <img src="/{{ author.logo }}" style="max-width: 100%;margin: 3px" />

View File

@ -0,0 +1,11 @@
---
layout: default
menu: ['global']
---
<ul class="columns">
{%- for doc in page.author_full.contributions -%}
<li>
<a href="{{ doc.url }}.html">{{ doc.title }}</a>
</li>
{%- endfor -%}
</ul>

View File

@ -7,9 +7,8 @@ menu: ['global']
<h3>{{ site.data.i18n[site.lang].label.tag_pages }} {{ page.tags }}</h3> <h3>{{ site.data.i18n[site.lang].label.tag_pages }} {{ page.tags }}</h3>
<div class="columns"> <div class="columns">
<ul> <ul>
{% include /functions/wiki-pages.html %}
{% for tag in page.tags %} {% for tag in page.tags %}
{% for other_page in wiki_pages %} {% for other_page in site.data.wiki_pages %}
{% if other_page.tags contains tag and other_page.id != page.id %} {% if other_page.tags contains tag and other_page.id != page.id %}
<li><a href="{{ other_page.url }}">{{ other_page.title }}</a></li> <li><a href="{{ other_page.url }}">{{ other_page.title }}</a></li>
{% endif %} {% endif %}

5
_layouts/user.html Normal file
View File

@ -0,0 +1,5 @@
---
layout: default
menu: ['global']
---
{{ content }}

View File

@ -0,0 +1,22 @@
module Jekyll
class ContributionsPageGenerator < Generator
def generate(site)
site.data['authors'].each do |author|
site.pages << ContributionsPage.new(site, author)
end
end
end
class ContributionsPage < Page
def initialize(site, author)
@site = site
@base = site.source
@name = "#{author['contributions_url']}.html"
self.process(@name)
self.read_yaml(File.join(@base, '_layouts'), 'contributions.html')
self.data['author_full'] = author
self.data['title'] = "Contributions by <a href=\"/#{site.data['i18n'][site.config['lang']]['prefix']['user']}#{author['id']}.html\">#{author['name']}</a>"
end
end
end

View File

@ -1,8 +1,45 @@
Jekyll::Hooks.register :documents, :pre_render do |post| Jekyll::Hooks.register :site, :post_read do |site|
user_pages = site.collections
.select { |key, collection| key.start_with?('special') }
.map { |key, collection| collection.docs }
.flatten
.select { |page| page.data['layout'] == 'user' }
wiki_pages = site.collections
.select { |key, collection| key.start_with?('wiki') }
.map { |key, collection| collection.docs }
.flatten
site.data['wiki_pages'] = wiki_pages
wiki_tags = wiki_pages
.map { |page| page.data['tags'] }
.flatten
.uniq
site.data['wiki_tags'] = wiki_tags
prefix = site.data['i18n'][site.config['lang']]['prefix']['user']
authors = site.data['users'].map do |user|
contributions = wiki_pages.select { |page| page.data['author'] == user[0] }
author = {'id' => user[0],
'name' => user[1]['name'],
'logo' => user[1]['logo'],
'url' => "/#{prefix}#{user[0]}",
'contributions' => contributions,
'contributions_count' => contributions.length,
'contributions_url' => "/#{prefix}#{user[0]}:Contributions"
}
user_pages.select { |page| page.url == author['url'] }
.each { |page| page.data['author_full'] = author }
author
end
site.data['authors'] = authors
wiki_pages.each do |page|
page.data['author_full'] = authors.select { |author| author['id'] == page.data['author'] }.first
end
end end
Jekyll::Hooks.register :documents, :post_render do |doc| Jekyll::Hooks.register :documents, :post_render do |doc|
# Jekyll.logger.info "Generating:", "Firing :pages, :post_render for : #{post.content}"
if doc.content then if doc.content then
doc.data['size']=doc.content.size doc.data['size']=doc.content.size
doc.data['bytes']=doc.content.bytesize doc.data['bytes']=doc.content.bytesize

View File

@ -70,6 +70,10 @@ a {
font-weight: bold; font-weight: bold;
font-size: 210%; font-size: 210%;
margin-bottom: 0.5em; margin-bottom: 0.5em;
a {
color: #424242;
}
} }
pre, code { pre, code {

View File

@ -1,5 +1,5 @@
--- ---
layout: simple layout: user
title: Alexis title: Alexis
created: 2019-04-12 created: 2019-04-12
modified: 2019-04-12 modified: 2019-04-12
@ -8,4 +8,9 @@ revisions:
date: 2019-04-12 date: 2019-04-12
comment: First version comment: First version
--- ---
I'm a developer. <div>
I'm a developer.
</div>
<div>
I've written <a href="{{ page.author_full.contributions_url }}">{{ page.author_full.contributions_count }} pages</a>
</div>