diff --git a/README-GENERATOR.md b/README-GENERATOR.md index 88aeeb7..649dfdf 100644 --- a/README-GENERATOR.md +++ b/README-GENERATOR.md @@ -27,6 +27,7 @@ The **Generator** forms the core of the pagination logic. It is responsible for * [Formatting page titles](#formatting-page-titles) * [Reading pagination meta information](#reading-pagination-meta-information) * [How to generate a JSON API](#generating-a-json-api) +* [Renaming pagination file names](#renaming-pagination-file-names) * [Common issues](#common-issues) - [Dependency Error after installing](#i-keep-getting-a-dependency-error-when-running-jekyll-serve-after-installing-this-gem) - [Bundler error upgrading gem (Bundler::GemNotFound)](#im-getting-a-bundler-error-after-upgrading-the-gem-bundlergemnotfound) @@ -94,6 +95,10 @@ pagination: # Internally this is set to html by default extension: html + # Optional, the default name of the index file for generated pages (e.g. 'index.html') + # Without file extension + indexpage: 'index' + ############################################################ ``` @@ -493,19 +498,16 @@ Delivering content via an API is useful, for a lot of the same reasons that pagi 1. Easy for the user to consume. 2. Easy for the browser to load. -Paginating content meets both of these requirements, but developers are limited to presenting content statically rather than dynamically. - -Some example of dynamic content delivery are: - +Paginating content meets both of these requirements, but developers are limited to presenting content statically rather than dynamically. Some example of dynamic content delivery are: - Pop up modals - Infinite scrolling - Multi-tiered pagination (e.g. Netflix UI horizontal scrolling for multiple movie categories) -How do I generate a JSON API for Jekyll? +### So how do I generate a JSON API for Jekyll? -First, create a new jekyll page. I'm going to call my page `siteAPI.md`. +First, create a new jekyll page and set its layout to `null` to avoid any extra html to show up. -Next, we're going to use the `extension` option to output the page as a JSON file. +Next, use the `extension` and `indexpage` option to customize the output of the page and its paginated content as JSON files. Here's an example page: ``` @@ -513,34 +515,82 @@ Here's an example page: layout: null permalink: /api pagination: + permalink: 'feed-:num' enabled: true extension: json + indexpage: 'feed-1' --- { - "pages": [ - {% for post in paginator.posts %} + "pages": [{% for post in paginator.posts %} + {% if forloop.first != true %},{% endif %} { "title": "{{ post.title }}", "link": "{{ post.url }}" - }, - {% endfor %} + }{% endfor %} ] } ``` +Next, run `jekyll build`. This will generate a set of paginated JSON files under the folder `/api`. These JSON files can be loaded via Javascript/AJAX to dynamically load content into your site. + +Below's an example set of routes that the configuration would generate: +- http://localhost:4000/api/feed-1.json +- http://localhost:4000/api/feed-2.json +- http://localhost:4000/api/feed-3.json + +And here is an example of one of the feed.json files that are created given the markup above +``` +{ + "pages": [ + { + "title": "Narcisse Snake Pits", + "link": "/2016/11/narcisse-snake-pits.html" + },{ + "title": "Luft-Fahrzeug-Gesellschaft", + "link": "/2016/11/luft-fahrzeug-gesellschaft.html" + },{ + "title": "Rotary engine", + "link": "/2016/11/rotary-engine.html" + } + ], + "next": "/api/feed-11.json", + "prev": "/api/feed-9.json", + "first": "/api/feed-1.json" +} +``` + +For further information see [Example 4](https://github.com/sverrirs/jekyll-paginate-v2/tree/master/examples/04-jsonapi), that project can serve as a starting point for your experiments with this feature. + +### How did you generate those 'next', 'prev' and 'first' links? -Next, run `jekyll build`. This will generate a set of paginated JSON files. +All the normal paginator variables can be used in these JSON feed files. You can use them to achive quite powerful features such as pre-loading and detecting when there are no more feeds to load. + +``` +{% if paginator.next_page %} + ,"next": "{{ paginator.next_page_path }}" + {% endif %} + {% if paginator.last_page %} + ,"prev": "{{ paginator.last_page_path }}" + {% endif %} + {% if paginator.first_page %} + ,"first": "{{ paginator.first_page_path }}" + {% endif %} +``` -After the build has completed the JSON files will be located in the `_site/api` directory. -The JSON files can be accessed over HTTP. +## Renaming pagination file names +By default the pagination system creates all paginated pages as `index.html`. The system provides an option to override this name and file extension with the -Here's an example set of routes: +```yml + indexpage: index + extension: html +``` -- http://localhost:4000/api/index.json -- http://localhost:4000/api/page/2/index.json -- http://localhost:4000/api/page/3/index.json +If you wanted to generate all pagination files as `default.htm` then the settings should be configured as follows -These routes can be fetched via AJAX to dynamically load content into your site. +```yml + indexpage: default + extension: htm +``` ## Common issues diff --git a/examples/01-typicalblog/_config.yml b/examples/01-typicalblog/_config.yml index dccbe4c..fc43fd7 100644 --- a/examples/01-typicalblog/_config.yml +++ b/examples/01-typicalblog/_config.yml @@ -33,6 +33,10 @@ exclude: # Produces a cleaner folder structure when using categories permalink: /:year/:month/:title.html +# Explicitly turn off the old code +paginate: nil +paginate_path: nil + # Pagination Settings pagination: enabled: true diff --git a/examples/03-tags/_config.yml b/examples/03-tags/_config.yml index 08bc8ba..528ccb7 100644 --- a/examples/03-tags/_config.yml +++ b/examples/03-tags/_config.yml @@ -70,6 +70,8 @@ pagination: limit: 0 sort_field: 'date' sort_reverse: true + # extension: htm + # indexpage: 'default' trail: before: 2 after: 2 \ No newline at end of file diff --git a/examples/04-jsonapi/Gemfile b/examples/04-jsonapi/Gemfile new file mode 100644 index 0000000..d81e666 --- /dev/null +++ b/examples/04-jsonapi/Gemfile @@ -0,0 +1,28 @@ +source "https://rubygems.org" +ruby RUBY_VERSION + +# Hello! This is where you manage which Jekyll version is used to run. +# When you want to use a different version, change it below, save the +# file and run `bundle install`. Run Jekyll with `bundle exec`, like so: +# +# bundle exec jekyll serve +# +# This will help ensure the proper Jekyll version is running. +# Happy Jekylling! +gem "jekyll", "~> 3.0" + +# This is the default theme for new Jekyll sites. You may change this to anything you like. +gem "minima", "~> 2.0" + +# If you want to use GitHub Pages, remove the "gem "jekyll"" above and +# uncomment the line below. To upgrade, run `bundle update github-pages`. +# gem "github-pages", group: :jekyll_plugins + +source 'https://rubygems.org' + +group :jekyll_plugins do + gem "jekyll-paginate-v2", "~> 1.7" + gem "jekyll-feed" +end + +gem 'wdm', '>= 0.1.0' if Gem.win_platform? diff --git a/examples/04-jsonapi/README.md b/examples/04-jsonapi/README.md new file mode 100644 index 0000000..96149dd --- /dev/null +++ b/examples/04-jsonapi/README.md @@ -0,0 +1,100 @@ +# Example 04::Dynamic JSON/AJAX API +This example site shows how the pagination gem can be used to generate JSON feed files that can be used to provide dynamically loaded content to your website using Javascript and AJAX/XHR calls. + +The site is generated using the jekyll built in new command `jekyll new myblog` and it uses the [default `minima` theme](https://github.com/jekyll/minima). + +After generating the pagination gem was installed using + +``` +gem install jekyll-paginate-v2 +``` + +## Structure + +The site contains a single index.html file and a few example posts. The index.html is responsible for generating the json feed files that contain information about the post content on the website. + +Below is an example content from one of the generated json files: + +``` +{ + "pages": [ + { + "title": "Narcisse Snake Pits", + "link": "/2016/11/narcisse-snake-pits.html" + },{ + "title": "Luft-Fahrzeug-Gesellschaft", + "link": "/2016/11/luft-fahrzeug-gesellschaft.html" + },{ + "title": "Rotary engine", + "link": "/2016/11/rotary-engine.html" + } + ], + "next": "/api/feed-3.json", + "prev": "/api/feed-1.json" +} +``` + +## Setup configuration + +The gem is added to the `_config.yml` file under +``` yml +gems: + - jekyll-paginate-v2 +``` + +as well as to the `Gemfile` into the main loop +``` ruby +group :jekyll_plugins do + gem "jekyll-paginate-v2" + gem "jekyll-feed" +end +``` + +At this point is is advisable to delete the `Gemfile.lock` file to clear out any potential issues with gem caching and dependency issues (no worries this file will be auto generated for you again). + +## Configuring the pagination + +The normal pagination for the site can be added to the `_config.yml` file as normal. +However it is advisable to configure the feed generating pages independantly of the main site pagination configuration. + +Therefore the `index.html` page contains the following frontmatter: + + +``` yml +--- +layout: null +permalink: /api +pagination: + permalink: 'feed-:num' + enabled: true + extension: json + indexpage: 'feed-1' +--- +``` + +## Completing the setup +Now you need to configure the generation of the JSON contents for your paginated files. Do this by specifying the following code in the body of the `index.html` page + +``` yml +{ + "pages": [{% for post in paginator.posts %} + {% if forloop.first != true %},{% endif %} + { + "title": "{{ post.title }}", + "link": "{{ post.url }}" + }{% endfor %} + ], + {% if paginator.next_page %} + ,"next": "{{ paginator.next_page_path }}" + {% endif %} + {% if paginator.previous_page %} + ,"prev": "{{ paginator.previous_page_path }}" + {% endif %} +} +``` + +That is it, no further configuration is needed! + +Try building the site yourself using `jekyll build` or `jekyll serve`. + +Cheers :heart: diff --git a/examples/04-jsonapi/_config.yml b/examples/04-jsonapi/_config.yml new file mode 100644 index 0000000..dccbe4c --- /dev/null +++ b/examples/04-jsonapi/_config.yml @@ -0,0 +1,51 @@ +# Welcome to Jekyll! +# +# This config file is meant for settings that affect your whole blog, values +# which you are expected to set up once and rarely edit after that. If you find +# yourself editing these this file very often, consider using Jekyll's data files +# feature for the data you need to update frequently. +# +# For technical reasons, this file is *NOT* reloaded automatically when you use +# 'bundle exec jekyll serve'. If you change this file, please restart the server process. + +# Site settings +# These are used to personalize your new site. If you look in the HTML files, +# you will see them accessed via {{ site.title }}, {{ site.email }}, and so on. +# You can create any custom variable you would like, and they will be accessible +# in the templates via {{ site.myvariable }}. +title: Paginate Example - 01 Typical Blog +email: jekyll@sverrirs.com +description: > # this means to ignore newlines until "baseurl:" + Shows how the jekyll-paginate-v2 gem can be used on a typical blog created in Jekyll. +baseurl: "" # the subpath of your site, e.g. /blog +url: "" # the base hostname & protocol for your site, e.g. http://example.com +github_username: sverrirs + +# Build settings +markdown: kramdown +theme: minima +gems: + - jekyll-paginate-v2 +exclude: + - Gemfile + - Gemfile.lock + +# Produces a cleaner folder structure when using categories +permalink: /:year/:month/:title.html + +# Pagination Settings +pagination: + enabled: true + per_page: 3 + permalink: '/page/:num/' + title: ':title - page :num of :max' + limit: 0 + sort_field: 'date' + sort_reverse: true + +############################################################ +# Old jekyll-paginate pagination logic +# Uncomment thew two entries below to demonstrate how this new gem +# retains backwards compatibility with the old pagination logic +#paginate: 3 +#paginate_path: "/legacy/page:num/" \ No newline at end of file diff --git a/examples/04-jsonapi/_posts/2016-11-20-geography-of-minneapolis.md b/examples/04-jsonapi/_posts/2016-11-20-geography-of-minneapolis.md new file mode 100644 index 0000000..1372e32 --- /dev/null +++ b/examples/04-jsonapi/_posts/2016-11-20-geography-of-minneapolis.md @@ -0,0 +1,29 @@ +--- +layout: post +title: Geography of Minneapolis +date: 2016-11-20 19:16:49 +0100 +categories: wikipedia +--- + +_From Wikipedia, the free encyclopedia_ + +Minneapolis is the largest city in the state of Minnesota in the United States, and the county seat of Hennepin County. + +## Physical +According to the United States Census Bureau, the city has a total area of 151.3 km² (58.4 mi²). 142.2 km² (54.9 mi²) of it is land and 9.1 km² (3.5 mi²) of it (6.01%) is water. The city center is located just south of 45 degrees north latitude. On the south side of Golden Valley Road just east of Wirth Parkway, a stone containing a weathered plaque marks a point on the 45th parallel.[1] The Mississippi, which runs to the southeast, directed the early growth of the city. Most early streets ran parallel to the river to maximize the amount of land that could be used. Eventually, growth of Minneapolis turned to north-south and east-west streets. Many unique intersections like Seven Corners on the eastern periphery of downtown were formed to translate between the two layouts. Some streets, especially older and more traditionally important ones like Hennepin Avenue and Nicollet Avenue, have both orientations at different points. + +## Parks and lakes +Minneapolis has a large park system consisting of ten square miles (26 km²) of land and water that is interlinked in many places. Theodore Wirth is often credited with the development of this system that brought a playground within the reach of most children and the canopy of trees and boulevards in much of the city. The Mississippi National River and Recreation Area connects regional parks and visitors centers. + +Theodore Wirth Park is the largest in the city, shared with Golden Valley, and is about 60% the size of Central Park in New York City. Minnehaha Park is one of the most famous, the site of Minnehaha Falls and cultural heritage events every year. Tower Hill Park in Prospect Park is the home of a 1913 water tower, one of the highest points in Minneapolis.[2] + +The Grand Rounds Scenic Byway circles through the city and many of the larger park areas including land along the Mississippi, lakes and scenic areas. A parkway for cars, a bikeway for riders, and a walkway for pedestrians run parallel paths along the 50-mile route. A growing number of bikeways and walkways crisscross the city and interconnect with neighboring cities. + +Twenty four small lakes are within the city limits.[3] Among the largest freshwater lakes to the west are Lake Harriet, Lake Calhoun, Lake of the Isles, and Cedar Lake, known together as the "Chain of Lakes". Lake Nokomis and Lake Hiawatha are to the east. Connected by bike, running and walking paths, Minneapolis lakes are used for swimming, fishing, picnics and boating. + +## Flora and fauna + +### Waterfalls +The area now occupied by the Twin Cities generally consisted of a 155 foot (47 m) thick layer of St. Peter Sandstone, under a 16 foot (5 m) thick layer of shale, under a 35 foot (11 m) thick layer of Platteville limestone.[4] These layers were the result of an Ordovician Period sea which covered east-central Minnesota 500 million years ago.[4] The hard limestone cap was formed from fossilized shell fish. About 20,000 years ago, the area was covered by the Superior Lobe of the Laurentide ice sheet, which left the St. Croix moraine on the Twin Cities as it receded.[4] Later the Grantsburg Sublobe of the Des Moines Lobe also covered the area.[5] Under these vast layers of ice, tunnel valleys were formed, cutting through the limestone layer with tremendous force, to release ice meltwater and glacier effluence.[6] The result was a series of troughs in the limestone, which were filled by glacial till and outwash deposit as the glaciers receded. Sometimes the sediment would be mixed with huge chunks of ice, which would leave voids in the soil. These voids created basins for the Twin Cities Lakes, such as Harriet and Lake Calhoun.[6] Connecting the city lakes in several north-south arteries are gorges cut through the bedrock, but filled with sand and sediment. + +When River Warren Falls receded past the confluence of the much smaller Upper Mississippi River, a new waterfall was created where that river entered the much-lower glacial River Warren. The new falls also receded upstream on the Mississippi, migrating eight miles (12875 m) over 9600 years to where Louis Hennepin first saw it and named St. Anthony Falls in 1680. Due to its value as a power source, this waterfall determined the location of Minneapolis. One branch of the river coming from the west, Minnehaha Creek receded only a few hundred yards from one of the channels of the Mississippi. Minnehaha Falls remains as a picturesque and informative relic of River Warren Falls, and the limestone-over-sandstone construction is readily apparent in its small gorge. \ No newline at end of file diff --git a/examples/04-jsonapi/_posts/2016-11-21-sailing-summer-olympics-1988.md b/examples/04-jsonapi/_posts/2016-11-21-sailing-summer-olympics-1988.md new file mode 100644 index 0000000..2f4eeed --- /dev/null +++ b/examples/04-jsonapi/_posts/2016-11-21-sailing-summer-olympics-1988.md @@ -0,0 +1,15 @@ +--- +layout: post +title: Sailing at the 1988 Summer Olympics +date: 2016-11-21 19:16:49 +0100 +categories: wikipedia +--- + +_From Wikipedia, the free encyclopedia_ + +Sailing/Yachting is an Olympic sport starting from the 1896 Olympics in Athens, Greece). With the exception of 1904 and possible 1916 sailing was always a part of the Olympic program. The Sailing program of 1988 consisted of a total of eight sailing classes (disciplines). For each class seven races were scheduled from September 20, 1988 to September 27, 1988 of the coast of Busan and was the first time that a separate event was allocated exclusively for women (sailed in the 470 class). The sailing was done on the triangular type Olympic courses. + +## Venue +According to the IOC statutes the contests in all sport disciplines must be held either in, or as close as possible to the city which the IOC has chosen. Since the sailing conditions of the coast near Seoul are not very suitable for Olympic sailing Busan was chosen for the 1988 Sailing event. A total of two race areas were created of the coast of Busan. + +Busan in Korea was reportedly a light wind venue but no one realised until too late that this information came from the airport which was located in a sheltered valley. It turned out to be that the 1988 Olympic Games were one of the windiest ever with one day of racing postponed due to too much wind. One day of racing saw around 30 knots of wind with 5 knots of current going against the wind. There was a lot of equipment damage and rescues for many classes resulting in many sailors did not finish and requests for redress. \ No newline at end of file diff --git a/examples/04-jsonapi/_posts/2016-11-22-rotary-engine.md b/examples/04-jsonapi/_posts/2016-11-22-rotary-engine.md new file mode 100644 index 0000000..f32e5ce --- /dev/null +++ b/examples/04-jsonapi/_posts/2016-11-22-rotary-engine.md @@ -0,0 +1,27 @@ +--- +layout: post +title: Rotary engine +date: 2016-11-22 19:16:49 +0100 +categories: wikipedia +--- + +_From Wikipedia, the free encyclopedia_ + +The rotary engine was an early type of internal-combustion engine, usually designed with an odd number of cylinders per row in a radial configuration, in which the crankshaft remained stationary in operation, with the entire crankcase and its attached cylinders rotating around it as a unit. Its main application was in aviation, although it also saw use before its primary aviation role, in a few early motorcycles and automobiles. + +This type of engine was widely used as an alternative to conventional inline engines (straight or V) during World War I and the years immediately preceding that conflict. It has been described as "a very efficient solution to the problems of power output, weight, and reliability".[1] + +By the early 1920s, however, the inherent limitations of this type of engine had rendered it obsolete, with the power output increasingly going into overcoming the air-resistance of the spinning engine itself. The rotating mass of the engine also caused significant gyroscopic precession: depending on the type of aircraft, this produced stability and control problems, especially for inexperienced pilots. Another factor in the demise of the rotary was the fundamentally inefficient total-loss oiling system, caused by the need to aspirate the fuel/air mixture through the hollow crankshaft and crankcase along with the lubricating medium, as in a two-stroke engine. + +## Description +A rotary engine is essentially a standard Otto cycle engine, but instead of having a fixed cylinder block with rotating crankshaft as with a conventional radial engine, the crankshaft remains stationary and the entire cylinder block rotates around it. In the most common form, the crankshaft was fixed solidly to the airframe, and the propeller was simply bolted to the front of the crankcase. + +Three key factors contributed to the rotary engine's success at the time:[2] + +* Smooth running: Rotaries delivered power very smoothly because (relative to the engine mounting point) there are no reciprocating parts, and the relatively large rotating mass of the crankcase/cylinders (as a unit) acted as a flywheel. +* Improved cooling: when the engine was running the rotating crankcase/cylinder assembly created its own fast-moving cooling airflow, even with the aircraft at rest. +* Weight advantage: many conventional engines had to have heavy flywheels added to smooth out power impulses and reduce vibration. Rotary engines gained a substantial power-to-weight ratio advantage by having no need for an added flywheel. They shared with other radial configuration engines the advantage of a small, flat crankcase, and because of their efficient air-cooling system cylinders could be made with thinner walls and shallower cooling fins, which further reduced their weight. + +Most rotary engines were arranged with the cylinders pointing outwards from a single crankshaft, in the same general form as a radial, but there were also rotary boxer engines[3] and even one-cylinder rotaries. + +Like radial engines, rotaries were generally built with an odd number of cylinders (usually either 7 or 9), so that a consistent every-other-piston firing order could be maintained, to provide smooth running. Rotary engines with an even number of cylinders were mostly of the "two row" type. \ No newline at end of file diff --git a/examples/04-jsonapi/_posts/2016-11-23-luft-fahrzeug-gesellschaft.md b/examples/04-jsonapi/_posts/2016-11-23-luft-fahrzeug-gesellschaft.md new file mode 100644 index 0000000..4df6303 --- /dev/null +++ b/examples/04-jsonapi/_posts/2016-11-23-luft-fahrzeug-gesellschaft.md @@ -0,0 +1,27 @@ +--- +layout: post +title: Luft-Fahrzeug-Gesellschaft +date: 2016-11-23 19:16:49 +0100 +categories: wikipedia +--- + +Luft-Fahrzeug-Gesellschaft, also referred to as LFG, was a German aircraft manufacturer during World War I. They are best known for their various "Roland" designs, notably the Roland C.II Walfisch (whale), Roland D.II haifisch (Shark) and Roland D.VI, although they also produced a number of airships and many experimental designs. + +## Airships +Luft-Fahrzeug-Gesellschaft formed on April 30, 1908, from the assets of an experimental airship engine company located in Bitterfeld, Motorluftschiff Studiengesellscaft (MStG). Additional funding for the new enterprise was provided primarily by Krupp, AEG, and a local chemical company. The company's offices were located in Berlin along with the factory at Adlershof. Manufacture was transferred to Charlottenburg following a fire on 6 September 1916, allegedly caused by the British Secret Service.[1] + +Their first project was an airship design by August von Parseval, a German airship designer. This entered service as the PL.II in 1910. During World War I, four were delivered to the German Army and Navy. In total some 25 "PL" airships were built, flown and delivered to various customers. The PL-26, one of the last, crashed on landing and burnt inside hangar Luftschiffhalle 2 with no fatalities. For the rest of the war the hangars were used mostly for repairs of observation balloons. + +## Aeroplanes + +In 1913 LFG started producing new designs under the trade name Roland to avoid confusion with the Luftverkehrsgesellschaft (L.V.G.) firm. In 1916 the company developed a floatplane version of the Albatros C.Ia as the LFG W. Some parts were built in Bitterfeld, but final assembly and checkout was carried out in new factories in Stralsund. + +Their first successful design was the Roland C.II Walfisch (whale), a two-seat reconnaissance biplane. It had a semi-monocoque fuselage, skinned with two layers of long plywood strips glued at opposing diagonal angles around a mold and skinned with fabric both inside and outside. The fuselage filled the full gap between the wings, leaving the pilot and observer/gunner over the top wings with an excellent view upward. The fuselage "half-shells" were each fitted onto a supporting framework of wooden formers and longerons. The "wrapping" technique of the long plywood strips for the outer fuselage surface led to this particular technique of manufacture being described in German as the Wickelrumpf (wrapped body) style of construction, and was subsequently patented by the firm,[2] licensing the construction method to Pfalz in 1917 for construction of their own single-seat fighter designs. Although it was said to have tricky handling, the Roland C.II had excellent performance, and was also used on long-range missions as a bomber escort. A version with the 200 hp Benz Bz.IV engine and new wing struts was built as the D.III, but only one prototype was ever built, as was the case for the 160 hp Mercedes D.III-powered C.V. + +The C.II was adapted to the pure fighter role as the Roland D.I, but in this role the poor forward view proved to be a problem. A fire at the factory severely constrained production, and only 20 were built. A newer version with a more conventional layout, the Roland D.II, followed, whose fuselage was reduced in height to leave a gap with the upper wing but was otherwise similar overall. The competing Albatros D.I was preferred, and only about 230 examples were built, which where then mostly used on the eastern front and in Macedonia. The fuselage to wing gap was further increased in the D.III, but the temperamental 180 hp Argus As.III limited production to only a handful. Six D.IIs were delivered in July 1917 to the Bulgarian Air Force, and six D.IIIs were delivered in May 1918.[3] + +Although the Wickelrumpf style of wood-structure monocoque fuselage was extremely strong, it was also very difficult and time-consuming to build. A new method of construction was introduced that used spruce planking running the length of the aircraft in place of the formed plywood, and the D.III was adapted using this technique to produce D.IV triplane and D.V biplane, both powered by the D.III's 160 hp Mercedes. The fuselage shell's construction technique for these aircraft resembled a clinker-planked boat hull in appearance when finished, and was named Klinkerrumpf (clinker body) construction, and was also patented by the firm.[4] A further adaptation of the D.IV with the 185 hp Benz Bz. III resulted in the Roland D.VI, which was entered in the First Fighter Competition trials at Adlershof in early 1918. Although the Fokker D.VII won that contest, the D.VI was also ordered into production as it used a different engine, and by the end of the war about 350 had been delivered. A large number of different versions using various engines were built as prototypes without entering production, as well as a triplane adaptation as the D.VI (also known as the Dr.I). + +The next major design from Roland were parasol monoplane designs, the D.XVI with the Siemens-Halske Sh.III or 170 hp Goebel Goe.IIIa rotary piston engines, and the otherwise similar D.XVII with the inline 185 hp BMW IIIa. Both were entered into the Second Fighter Competition at Adlershof, but lost to the Fokker D.VIII. + +After the war all aircraft production in Germany was banned, and the company was forced to close the Bitterfeld plant and reopen in Seddin, producing airplanes, balloons and life boats. In 1933, aircraft production shut down. Three additional Parseval pattern airships were also built during this period. \ No newline at end of file diff --git a/examples/04-jsonapi/_posts/2016-11-24-narcisse-snake-pits.md b/examples/04-jsonapi/_posts/2016-11-24-narcisse-snake-pits.md new file mode 100644 index 0000000..e890ff6 --- /dev/null +++ b/examples/04-jsonapi/_posts/2016-11-24-narcisse-snake-pits.md @@ -0,0 +1,18 @@ +--- +layout: post +title: Narcisse Snake Pits +date: 2016-11-24 19:16:49 +0100 +categories: wikipedia +--- + +_From Wikipedia, the free encyclopedia_ + +The Narcisse Snake Pits are located in the Rural Municipality of Armstrong about 6 kilometres (3.7 mi) north of Narcisse, Manitoba, Canada. The dens are the winter home of tens of thousands of red-sided garter snakes (Thamnophis sirtalis parietalis). These pits are the largest concentration in the world of this particular type of snake. Their winter dens are subterranean caverns formed by the area's water-worn limestone bedrock. In the spring, they come up from their dens to the snake pits, where they engage in mating rituals. Then they disperse into the nearby marshes for the summer. + +## Conservation +The population of red-sided garter snakes around Narcisse was roughly 70,000 until terrible weather in 1999 killed tens of thousands of them before they could reach their winter dens. [1] This tragedy triggered concern about the snakes' biannual migratory path, which cuts right across Highway 17. Every year, ten thousand snakes trying to get to or from their winter dens had been crushed under the wheels of vehicles. This had not been a problem before, because the vast population compensated for the losses. After the winter of 1999, however, the population of garter snakes was dangerously low, causing Manitoba Hydro and volunteers to intervene. + +Foot-high snow fences were built to force snakes into six-inch (15-cm) tunnels that went under Highway 17. Since some snakes still managed to squeeze under the fence and onto the road, signs were put up during the migratory season urging motorists to slow down to avoid accidentally driving over snakes. These measures worked, and now less than a thousand snakes per season are killed on the highway. + +## Visiting +The conservation area is open to the public. The snakes are most active during the spring and fall - in late April to early May, which is the mating season, and also in early September, when the snakes slither back down to their winter dens.[1] \ No newline at end of file diff --git a/examples/04-jsonapi/_posts/2016-11-25-tele7jours.md b/examples/04-jsonapi/_posts/2016-11-25-tele7jours.md new file mode 100644 index 0000000..ee8714e --- /dev/null +++ b/examples/04-jsonapi/_posts/2016-11-25-tele7jours.md @@ -0,0 +1,43 @@ +--- +layout: post +title: Télé 7 Jours +date: 2016-11-25 19:16:49 +0100 +categories: wikipedia +--- + +_From Wikipedia, the free encyclopedia_ + +***Télé 7 Jours*** is a [French] weekly magazine published by [Hachette Filipacchi Médias] in [France]. It publishes news and materials relating to French radio and television programming. + +## History and profile + +Originally, the magazine was named “Radio 44” as it started publishing on 29 October 1944. The name would change (“Radio 45”, “Radio 46”, etc.) as the year of publication changed, until the year 1957, when it was renamed “Radio Télévision 57” and in 1959 was changed to “Télé 59”. Its contents are basically coverage of television news and listings, cultural and lifestyle news and entertainment. + +In 1960, Sofirad, the original owner, sold the magazine to [Jean Prouvost], who named it “7 jours Télé 60” for a short period and then renamed it to the present “Télé 7 Jours” from 7 March 1960. + +The magazine is published on a weekly basis.[\[1\]] Its circulation jumped to more than a million copies weekly in 1962 and 2 million by 1965 becoming the biggest circulation weekly in France. + +In 1976, [Hachette][Hachette Filipacchi Médias] purchased the magazine.[\[2\]] The magazine remained the most read French magazine in the 1980s and 1990s reaching a circulation of 3.2 million weekly. + +From 1985 to 2003, *Télé 7 Jours* organized a French television production award (similar in nature to the [Emmy Awards]) called the *[7 d’Or]*.[\[2\]] From 1996 to 1999, [Benjamin Cuq] worked as reporter for *Télé 7 Jours*. + +## Circulation + +Télé 7 Jours had a circulation of 2,800,000 copies in 1974.[3] The circulation of the weekly was 2,606,000 copies in 1999.[4] + +It was the sixth best-selling television magazine worldwide with a circulation of 2,371,000 copies during in 2001.[1] In 2005 its circulation dropped to 1,892,000 copies, but it was the best-selling magazine in France.[5] + +The circulation of the magazine was 1,588,000 copies during the 2007-2008 period.[6] In 2010 the magazine had a circulation of 1,471,593 copies.[7] Its circulation was 1,225,642 copies in 2014. + + + [French]: /wiki/French_language "French language" + [Hachette Filipacchi Médias]: /wiki/Hachette_Filipacchi_M%C3%A9dias "Hachette Filipacchi Médias" + [France]: /wiki/France "France" + [edit]: /w/index.php?title=T%C3%A9l%C3%A9_7_Jours&action=edit§ion=1 "Edit section: History and profile" + [Jean Prouvost]: /wiki/Jean_Prouvost "Jean Prouvost" + [\[1\]]: #cite_note-mags-1 + [\[2\]]: #cite_note-rich-2 + [Emmy Awards]: /wiki/Emmy_Award "Emmy Award" + [7 d’Or]: /wiki/7_d%27Or "7 d'Or" + [Benjamin Cuq]: /wiki/Benjamin_Cuq "Benjamin Cuq" + [1]: /w/index.php?title=T%C3%A9l%C3%A9_7_Jours&action=edit§ion=2 "Edit section: Circulation" \ No newline at end of file diff --git a/examples/04-jsonapi/_posts/2016-11-26-columbia-river.md b/examples/04-jsonapi/_posts/2016-11-26-columbia-river.md new file mode 100644 index 0000000..3022a71 --- /dev/null +++ b/examples/04-jsonapi/_posts/2016-11-26-columbia-river.md @@ -0,0 +1,41 @@ +--- +layout: post +title: Columbia River +date: 2016-11-26 19:16:49 +0100 +categories: wikipedia +--- + +_From Wikipedia, the free encyclopedia_ + +The **Columbia River** is the largest river in the [Pacific Northwest] region of North America.[\[9\]] The river rises in the [Rocky Mountains] of [British Columbia], Canada. It flows northwest and then south into the US state of [Washington], then turns west to form most of the border between Washington and the state of [Oregon] before emptying into the Pacific Ocean. The river is 1,243 miles (2,000 km) long, and its largest [tributary] is the [Snake River]. Its [drainage basin] is roughly the size of France and extends into seven US states and a Canadian province. + +By volume, the Columbia is the fourth-largest river in the United States; it has the greatest flow of any North American river draining into the Pacific. The river’s heavy flow and relatively steep [gradient] gives it tremendous potential for the generation of electricity. The [14 hydroelectric dams] on the Columbia’s [main stem] and many more on its tributaries produce more than 44% of total U.S. [hydroelectric generation][\[10\]] – much more hydroelectric power than those of any other North American river. + +The Columbia and its tributaries have been central to the region’s culture and economy for thousands of years. They have been used for transportation since ancient times, linking the many cultural groups of the region. The river system hosts many species of anadromous fish, which migrate between freshwater habitats and the [saline] waters of the Pacific Ocean. These fish—especially the [salmon] species—provided the core subsistence for native peoples; in past centuries, Indigenous peoples traveled across western North America to the Columbia to trade for fish. + +In the late 18th century, a private American ship became the first non-indigenous vessel to enter the river; it was followed by a British explorer, who navigated past the [Oregon Coast Range] into the [Willamette Valley]. In the following decades, [fur trading] companies used the Columbia as a key transportation route. Overland explorers entered the Willamette Valley through the scenic but treacherous [Columbia River Gorge], and pioneers began to settle the valley in increasing numbers, following both routes to enter it. [Steamships] along the river linked communities and facilitated trade; the arrival of railroads in the late 19th century, many running along the river, supplemented these links. + + [Oregon Coast Range]: /wiki/Oregon_Coast_Range "Oregon Coast Range" + [Willamette Valley]: /wiki/Willamette_Valley "Willamette Valley" + [fur trading]: /wiki/Fur_trade "Fur trade" + [Columbia River Gorge]: /wiki/Columbia_River_Gorge "Columbia River Gorge" + [Steamships]: /wiki/Steamship "Steamship" + + [saline]: /wiki/Saline_water "Saline water" + [salmon]: /wiki/Salmon "Salmon" + + [gradient]: /wiki/Grade_(slope) "Grade (slope)" + [14 hydroelectric dams]: /wiki/List_of_dams_in_the_Columbia_River_watershed "List of dams in the Columbia River watershed" + [main stem]: /wiki/Main_stem "Main stem" + [hydroelectric generation]: /wiki/Hydroelectricity "Hydroelectricity" + [\[10\]]: #cite_note-IEA2014-10 + + [Pacific Northwest]: /wiki/Pacific_Northwest "Pacific Northwest" + [\[9\]]: #cite_note-9 + [Rocky Mountains]: /wiki/Rocky_Mountains "Rocky Mountains" + [British Columbia]: /wiki/British_Columbia "British Columbia" + [Washington]: /wiki/Washington_(state) "Washington (state)" + [Oregon]: /wiki/Oregon "Oregon" + [tributary]: /wiki/Tributary "Tributary" + [Snake River]: /wiki/Snake_River "Snake River" + [drainage basin]: /wiki/Drainage_basin "Drainage basin" \ No newline at end of file diff --git a/examples/04-jsonapi/_posts/2016-11-27-welcome-to-jekyll-paginate-v2.md b/examples/04-jsonapi/_posts/2016-11-27-welcome-to-jekyll-paginate-v2.md new file mode 100644 index 0000000..601cdda --- /dev/null +++ b/examples/04-jsonapi/_posts/2016-11-27-welcome-to-jekyll-paginate-v2.md @@ -0,0 +1,33 @@ +--- +layout: post +title: "Welcome to Jekyll Paginate V2!" +date: 2016-11-27 19:16:49 +0100 +categories: jekyll paginate +--- +You’ll find this post in your `_posts` directory. This post along with all of the other example posts is paginated by the new [jekyll-paginate-v2 gem](https://github.com/sverrirs/jekyll-paginate-v2). + +This pagination gem is built specially for Jekyll 3 and newer and is intended to replace the now discontinuted jekyll-paginate gem. + +This v2 of the gem offers full backwards compatibility with the old gem and its site configuration. You can simply replace the old jekyll-paginate gem with this one and your sites will still work without any changes. + +However to access the new enhanced features of this gem, like pagination on categories, tags and locales, then you need to remove the old jekyll-paginate configuration and activate the new `pagination:` [site configuration](https://github.com/sverrirs/jekyll-paginate-v2#site-configuration). + +The [source code](https://github.com/sverrirs/jekyll-paginate-v2/tree/master/examples) for this example project will show you all the necessary steps. + +## Installing + +Go ahead and install the latest version of the gem from [rubygems.org](https://rubygems.org/gems/jekyll-paginate-v2) + +``` +gem install jekyll-paginate-v2 +``` + +Replace the `jekyll-paginate` gem with `jekyll-paginate-v2` in both your `_config.yml` and your `Gemfile`. + +Now go ahead and re-build your site to start running the new pagination logic. You can rebuild the site in many different ways, but the most common way is to run `jekyll serve`, which launches a web server and auto-regenerates your site when a file is updated. + +Please see the [GitHub repo](https://github.com/sverrirs/jekyll-paginate-v2) to learn how to get the most out of this new pagination gem. There we also discuss the gems more advanced features. + +Please file all bugs/feature requests in the issues section of the [GitHub repo](https://github.com/sverrirs/jekyll-paginate-v2/issues). + +Have a great day :) diff --git a/examples/04-jsonapi/index.html b/examples/04-jsonapi/index.html new file mode 100644 index 0000000..5032e29 --- /dev/null +++ b/examples/04-jsonapi/index.html @@ -0,0 +1,25 @@ +--- +layout: null +permalink: /api +pagination: + permalink: 'feed-:num' + enabled: true + extension: json + indexpage: 'feed-1' +--- + +{ + "pages": [{% for post in paginator.posts %} + {% if forloop.first != true %},{% endif %} + { + "title": "{{ post.title }}", + "link": "{{ post.url }}" + }{% endfor %} + ], + {% if paginator.next_page %} + ,"next": "{{ paginator.next_page_path }}" + {% endif %} + {% if paginator.previous_page %} + ,"prev": "{{ paginator.previous_page_path }}" + {% endif %} +} \ No newline at end of file diff --git a/lib/jekyll-paginate-v2/generator/compatibilityUtils.rb b/lib/jekyll-paginate-v2/generator/compatibilityUtils.rb index 2e52228..04e7063 100644 --- a/lib/jekyll-paginate-v2/generator/compatibilityUtils.rb +++ b/lib/jekyll-paginate-v2/generator/compatibilityUtils.rb @@ -82,7 +82,7 @@ def self.in_hierarchy(source, page_dir, paginate_path) def self.paginate(legacy_config, all_posts, page, page_add_lambda ) pages = Utils.calculate_number_of_pages(all_posts, legacy_config['per_page'].to_i) (1..pages).each do |num_page| - pager = Paginator.new( legacy_config['per_page'], page.url, legacy_config['permalink'], all_posts, num_page, pages ) + pager = Paginator.new( legacy_config['per_page'], page.url, legacy_config['permalink'], all_posts, num_page, pages, '', '' ) if num_page > 1 template_full_path = File.join(page.site.source, page.path) template_dir = File.dirname(page.path) diff --git a/lib/jekyll-paginate-v2/generator/defaults.rb b/lib/jekyll-paginate-v2/generator/defaults.rb index d65f46f..8cddd3a 100644 --- a/lib/jekyll-paginate-v2/generator/defaults.rb +++ b/lib/jekyll-paginate-v2/generator/defaults.rb @@ -16,6 +16,8 @@ module PaginateV2::Generator 'before' => 0, # Limits how many links to show before the current page in the pagination trail (0, means off, default: 0) 'after' => 0, # Limits how many links to show after the current page in the pagination trail (0 means off, default: 0) }, + 'indexpage' => 'index', # The default name of the index pages + 'extension' => 'html', # The default extension for the output pages 'debug' => false, # Turns on debug output for the gem 'legacy' => false # Internal value, do not use (will be removed after 2018-01-01) } diff --git a/lib/jekyll-paginate-v2/generator/paginationGenerator.rb b/lib/jekyll-paginate-v2/generator/paginationGenerator.rb index 44efce5..3e59041 100644 --- a/lib/jekyll-paginate-v2/generator/paginationGenerator.rb +++ b/lib/jekyll-paginate-v2/generator/paginationGenerator.rb @@ -26,9 +26,10 @@ def generate(site) # Compatibility Note: (REMOVE AFTER 2018-01-01) # If the legacy paginate logic is configured then read those values and merge with config if !site.config['paginate'].nil? + Jekyll.logger.info "Pagination:","Legacy paginate configuration settings detected and will be used." # You cannot run both the new code and the old code side by side if !site.config['pagination'].nil? - err_msg = "The new jekyll-paginate-v2 and the old jekyll-paginate logic cannot both be configured in the site config at the same time. Please disable the old 'paginate:' config settings." + err_msg = "The new jekyll-paginate-v2 and the old jekyll-paginate logic cannot both be configured in the site config at the same time. Please disable the old 'paginate:' config settings by either omitting the values or setting them to 'paginate:off'." Jekyll.logger.error err_msg raise ArgumentError.new(err_msg) end diff --git a/lib/jekyll-paginate-v2/generator/paginationModel.rb b/lib/jekyll-paginate-v2/generator/paginationModel.rb index f979e86..9efbc59 100644 --- a/lib/jekyll-paginate-v2/generator/paginationModel.rb +++ b/lib/jekyll-paginate-v2/generator/paginationModel.rb @@ -262,6 +262,11 @@ def paginate(template, config, site_title, all_posts, all_tags, all_categories, # list of all newly created pages newpages = [] + # Consider the default index page name and extension + indexPageName = config['indexpage'].split('.')[0] + indexPageExt = Utils.ensure_leading_dot(config['extension']) + indexPageWithExt = indexPageName + indexPageExt + # Now for each pagination page create it and configure the ranges for the collection # This .pager member is a built in thing in Jekyll and defines the paginator implementation # Simpy override to use mine @@ -269,7 +274,7 @@ def paginate(template, config, site_title, all_posts, all_tags, all_categories, # 1. Create the in-memory page # External Proc call to create the actual page for us (this is passed in when the pagination is run) - newpage = PaginationPage.new( template, cur_page_nr, total_pages ) + newpage = PaginationPage.new( template, cur_page_nr, total_pages, indexPageWithExt ) # 2. Create the url for the in-memory page (calc permalink etc), construct the title, set all page.data values needed paginated_page_url = config['permalink'] @@ -282,17 +287,17 @@ def paginate(template, config, site_title, all_posts, all_tags, all_categories, paginated_page_url = File.join(first_index_page_url, paginated_page_url) # 3. Create the pager logic for this page, pass in the prev and next page numbers, assign pager to in-memory page - newpage.pager = Paginator.new( config['per_page'], first_index_page_url, paginated_page_url, using_posts, cur_page_nr, total_pages) + newpage.pager = Paginator.new( config['per_page'], first_index_page_url, paginated_page_url, using_posts, cur_page_nr, total_pages, indexPageName, indexPageExt) # Create the url for the new page, make sure we prepend any permalinks that are defined in the template page before if newpage.pager.page_path.end_with? '/' - newpage.set_url(File.join(newpage.pager.page_path, 'index.html')) - elsif newpage.pager.page_path.end_with? '.html' + newpage.set_url(File.join(newpage.pager.page_path, indexPageWithExt)) + elsif newpage.pager.page_path.end_with? indexPageExt # Support for direct .html files newpage.set_url(newpage.pager.page_path) else # Support for extensionless permalinks - newpage.set_url(newpage.pager.page_path+'.html') + newpage.set_url(newpage.pager.page_path+indexPageExt) end if( template.data['permalink'] ) diff --git a/lib/jekyll-paginate-v2/generator/paginationPage.rb b/lib/jekyll-paginate-v2/generator/paginationPage.rb index 7e81f06..494cda9 100644 --- a/lib/jekyll-paginate-v2/generator/paginationPage.rb +++ b/lib/jekyll-paginate-v2/generator/paginationPage.rb @@ -9,13 +9,15 @@ module PaginateV2::Generator # This page exists purely in memory and is not read from disk # class PaginationPage < Page - def initialize(page_to_copy, cur_page_nr, total_pages) + def initialize(page_to_copy, cur_page_nr, total_pages, index_pageandext) @site = page_to_copy.site @base = '' @url = '' + @name = index_pageandext.nil? ? 'index.html' : index_pageandext + + self.process(@name) # Creates the basename and ext member values # Only need to copy the data part of the page as it already contains the layout information - #self.data = Marshal.load(Marshal.dump(page_to_copy.data)) # Deep copying, http://stackoverflow.com/a/8206537/779521 self.data = Jekyll::Utils.deep_merge_hashes( page_to_copy.data, {} ) if !page_to_copy.data['autopage'] self.content = page_to_copy.content @@ -28,14 +30,7 @@ def initialize(page_to_copy, cur_page_nr, total_pages) end # Store the current page and total page numbers in the pagination_info construct - self.data['pagination_info'] = {"curr_page" => cur_page_nr, 'total_pages' => total_pages } - - # Set the page extension - extension = self.data['pagination']['extension'] - extension = extension.nil? ? '.html': '.' + extension - @name = 'index' + extension - - self.process(@name) # Creates the basename and ext member values + self.data['pagination_info'] = {"curr_page" => cur_page_nr, 'total_pages' => total_pages } # Perform some validation that is also performed in Jekyll::Page validate_data! page_to_copy.path diff --git a/lib/jekyll-paginate-v2/generator/paginator.rb b/lib/jekyll-paginate-v2/generator/paginator.rb index 5a021c5..0f3acd1 100644 --- a/lib/jekyll-paginate-v2/generator/paginator.rb +++ b/lib/jekyll-paginate-v2/generator/paginator.rb @@ -19,7 +19,7 @@ def page_trail=(page_array) # Initialize a new Paginator. # - def initialize(config_per_page, first_index_page_url, paginated_page_url, posts, cur_page_nr, num_pages) + def initialize(config_per_page, first_index_page_url, paginated_page_url, posts, cur_page_nr, num_pages, default_indexpage, default_ext) @page = cur_page_nr @per_page = config_per_page.to_i @total_pages = num_pages @@ -31,6 +31,24 @@ def initialize(config_per_page, first_index_page_url, paginated_page_url, posts, init = (@page - 1) * @per_page offset = (init + @per_page - 1) >= posts.size ? posts.size : (init + @per_page - 1) + # Adjust the first index page url + if( first_index_page_url.end_with?('/')) + first_index_page_url = first_index_page_url + default_indexpage + default_ext + puts "Appending default index+ext: #{first_index_page_url}" + elsif !first_index_page_url.include?('.') + first_index_page_url = first_index_page_url + default_indexpage + puts "Appending default index only: #{first_index_page_url}" + end + + # Adjust the paginated pages as well + if( paginated_page_url.end_with?('/')) + paginated_page_url = paginated_page_url + default_indexpage + default_ext + puts "Appending default paginated index+ext: #{paginated_page_url}" + elsif !paginated_page_url.include?('.') + paginated_page_url = paginated_page_url + default_ext + puts "Appending default paginated ext only: #{paginated_page_url}" + end + @total_posts = posts.size @posts = posts[init..offset] @page_path = @page == 1 ? first_index_page_url : Utils.format_page_number(paginated_page_url, cur_page_nr, @total_pages) diff --git a/lib/jekyll-paginate-v2/generator/utils.rb b/lib/jekyll-paginate-v2/generator/utils.rb index f5cb08f..ecff844 100644 --- a/lib/jekyll-paginate-v2/generator/utils.rb +++ b/lib/jekyll-paginate-v2/generator/utils.rb @@ -32,6 +32,17 @@ def self.format_page_number(toFormat, cur_page_nr, total_page_count=nil) def self.format_page_title(toFormat, title, cur_page_nr=nil, total_page_count=nil) return format_page_number(toFormat.sub(':title', title.to_s), cur_page_nr, total_page_count) end #function format_page_title + + # Static: Return a String version of the input which has a leading dot. + # If the input already has a dot in position zero, it will be + # returned unchanged. + # + # path - a String path + # + # Returns the path with a leading slash + def self.ensure_leading_dot(path) + path[0..0] == "." ? path : ".#{path}" + end # Static: Return a String version of the input which has a leading slash. # If the input already has a forward slash in position zero, it will be diff --git a/lib/jekyll-paginate-v2/version.rb b/lib/jekyll-paginate-v2/version.rb index be73c03..7e41766 100644 --- a/lib/jekyll-paginate-v2/version.rb +++ b/lib/jekyll-paginate-v2/version.rb @@ -1,8 +1,8 @@ module Jekyll module PaginateV2 - VERSION = "1.8.2" + VERSION = "1.9.0" # When modifying remember to issue a new tag command in git before committing, then push the new tag - # git tag -a v1.8.2 -m "Gem v1.8.2" + # git tag -a v1.9.0 -m "Gem v1.9.0" # git push origin --tags # Yanking a published Gem # gem yank jekyll-paginate-v2 -v VERSION diff --git a/spec/generator/paginator_spec.rb b/spec/generator/paginator_spec.rb index 35e6ab3..d690a34 100644 --- a/spec/generator/paginator_spec.rb +++ b/spec/generator/paginator_spec.rb @@ -6,7 +6,7 @@ module Jekyll::PaginateV2::Generator it "must include the necessary paginator attributes" do # config_per_page, first_index_page_url, paginated_page_url, posts, cur_page_nr, num_pages - pager = Paginator.new(10, "index.html", "/page:num/", [], 1, 10) + pager = Paginator.new(10, "index.html", "/page:num/", [], 1, 10, 'index', '.html') # None of these accessors should throw errors, just run through them to test val = pager.page @@ -22,10 +22,10 @@ module Jekyll::PaginateV2::Generator end it "must throw an error if the current page number is greater than the total pages" do - err = -> { pager = Paginator.new(10, "index.html", "/page:num/", [], 10, 8) }.must_raise RuntimeError + err = -> { pager = Paginator.new(10, "index.html", "/page:num/", [], 10, 8, 'index', '.html') }.must_raise RuntimeError # No error should be raised below - pager = Paginator.new(10, "index.html", "/page:num/", [], 8, 10) + pager = Paginator.new(10, "index.html", "/page:num/", [], 8, 10, 'index', '.html') end it "must trim the list of posts correctly based on the cur_page_nr and per_page" do @@ -35,7 +35,7 @@ module Jekyll::PaginateV2::Generator # Initialize a pager with # 5 posts per page # at page 2 out of 5 pages - pager = Paginator.new(5, "index.html", "/page:num/", posts, 2, 5) + pager = Paginator.new(5, "index.html", "/page:num/", posts, 2, 5, '', '') pager.page.must_equal 2 pager.per_page.must_equal 5 @@ -60,7 +60,7 @@ module Jekyll::PaginateV2::Generator # Initialize a pager with # 5 posts per page # at page 2 out of 5 pages - pager = Paginator.new(5, "index.html", "/page:num/", posts, 1, 5) + pager = Paginator.new(5, "index.html", "/page:num/", posts, 1, 5, '', '') pager.page.must_equal 1 pager.per_page.must_equal 5 @@ -85,7 +85,7 @@ module Jekyll::PaginateV2::Generator # Initialize a pager with # 5 posts per page # at page 2 out of 5 pages - pager = Paginator.new(5, "index.html", "/page:num/", posts, 5, 5) + pager = Paginator.new(5, "index.html", "/page:num/", posts, 5, 5, '', '') pager.page.must_equal 5 pager.per_page.must_equal 5 @@ -103,5 +103,55 @@ module Jekyll::PaginateV2::Generator pager.next_page_path.must_be_nil end + it "must create the explicit index page and index extension when specified" do + # Create a dummy list of posts that is easy to track + posts = ['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'] + + # Initialize a pager with + # 5 posts per page + # at page 2 out of 5 pages + pager = Paginator.new(5, "index.html", "/page:num/", posts, 2, 5, 'index', '.html') + + pager.page.must_equal 2 + pager.per_page.must_equal 5 + pager.total_pages.must_equal 5 + + pager.total_posts.must_equal 35 + + pager.posts.size.must_equal 5 + pager.posts[0].must_equal '6' + pager.posts[4].must_equal '10' + + pager.previous_page.must_equal 1 + pager.previous_page_path.must_equal 'index.html' + pager.next_page.must_equal 3 + pager.next_page_path.must_equal '/page3/index.html' + end + + it "must create the explicit index page and index extension when specified" do + # Create a dummy list of posts that is easy to track + posts = ['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'] + + # Initialize a pager with + # 5 posts per page + # at page 2 out of 5 pages + pager = Paginator.new(5, "/", "/feed:num", posts, 2, 5, 'feed', '.json') + + pager.page.must_equal 2 + pager.per_page.must_equal 5 + pager.total_pages.must_equal 5 + + pager.total_posts.must_equal 35 + + pager.posts.size.must_equal 5 + pager.posts[0].must_equal '6' + pager.posts[4].must_equal '10' + + pager.previous_page.must_equal 1 + pager.previous_page_path.must_equal '/feed.json' + pager.next_page.must_equal 3 + pager.next_page_path.must_equal '/feed3.json' + end + end end