├── .gitignore ├── .rspec ├── .rubocop.yml ├── .travis.yml ├── CHANGELOG.md ├── Gemfile ├── LICENSE ├── README.md ├── Rakefile ├── bin ├── console └── setup ├── jekyll-graph.gemspec ├── lib ├── jekyll-graph.rb └── jekyll-graph │ ├── config.rb │ ├── jekyll-graph.js │ ├── patch │ ├── context.rb │ └── page.rb │ ├── tags.rb │ └── version.rb └── spec ├── fixtures ├── _docs_net_web │ ├── blank.a.md │ ├── link.block.md │ ├── link.md │ └── link.missing-doc.md ├── _docs_tree │ ├── blank.missing-lvl.md │ ├── root.md │ ├── second-level.md │ └── second-level.third-level.md ├── _docs_web │ ├── blank.a.md │ ├── link.block.md │ ├── link.md │ └── link.missing-doc.md ├── _posts │ └── 2020-12-08-one-post.md ├── assets │ └── image.png └── one-page.md ├── jekyll-graph ├── feature_basic_default_namespaces_tree_spec.rb ├── feature_basic_default_net_web_spec.rb ├── feature_basic_default_sem_tree_spec.rb ├── feature_basic_default_web_spec.rb ├── feature_config_spec.rb └── version_spec.rb └── spec_helper.rb /.gitignore: -------------------------------------------------------------------------------- 1 | # Ruby Gem 2 | *.gem 3 | .bundle 4 | Gemfile.lock 5 | **/vendor/bundle 6 | /pkg/ 7 | 8 | # Jekyll cache & metadata 9 | .jekyll-cache/ 10 | .jekyll-metadata 11 | _site/ 12 | 13 | # rspec 14 | spec/fixtures/_site 15 | spec/*fixtures/**/.jekyll-cache 16 | # rspec failure tracking 17 | .rspec_status 18 | 19 | # macos 20 | .DS_Store 21 | 22 | /.yardoc 23 | /_yardoc/ 24 | /coverage/ 25 | /doc/ 26 | /spec/reports/ 27 | /tmp/ 28 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --format documentation 2 | --color 3 | --require spec_helper 4 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | AllCops: 2 | TargetRubyVersion: 2.4 3 | 4 | Style/StringLiterals: 5 | Enabled: true 6 | EnforcedStyle: double_quotes 7 | 8 | Style/StringLiteralsInInterpolation: 9 | Enabled: true 10 | EnforcedStyle: double_quotes 11 | 12 | Layout/LineLength: 13 | Max: 120 14 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: ruby 3 | cache: bundler 4 | rvm: 5 | - 3.0.0 6 | before_install: gem install bundler -v 2.2.17 7 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [0.0.11] - 2023-10-06 2 | ### Change 3 | - `net-web` -> `web`. 4 | ## [0.0.10] - 2023-09-25 5 | ### Fix 6 | - Dependencies 7 | ## [0.0.9] - 2023-09-25 8 | ### Change 9 | - Update plugin to support both `jekyll-namespaces` and `jekyll-semtree`. 10 | ## [0.0.8] - 2022-03-03 11 | ### Change 12 | - Update javascript setup instructions in README. 13 | ### Fix 14 | - Check 'visited' localstorage variable is not null. 15 | ## [0.0.7] - 2022-01-27 16 | ### Change 17 | - Bump jekyll-wikilinks version number (0.0.11). 18 | ## [0.0.6] - 2022-01-24 19 | ### Change 20 | - Move jekyll patch files to patch/ dir. 21 | - Bump jekyll-wikilinks version number (0.0.10). 22 | ## [0.0.5] - 2021-11-23 23 | ### Change 24 | - 'relatives' -> 'lineage' for tree nodes. 25 | ## [0.0.4] - 2021-11-22 26 | ### Fix 27 | - Custom path config related fix in scripts. 28 | ## [0.0.3] - 2021-11-22 29 | ### Change 30 | - Fix javascript inheritance. 31 | - Decrement missing node log messages from 'warn' to 'debug'. 32 | - Update license. 33 | ### Fix 34 | - Display log messages related to dependencies (see [#2](https://github.com/manunamz/jekyll-graph/issues/2)). 35 | - Custom path configs. 36 | ## [0.0.2] - 2021-09-17 37 | ### Change 38 | - Liquid tag `force-graph` -> `jekyll_graph`. 39 | ## [0.0.1] - 2021-09-17 40 | - Initial release 41 | ### Added 42 | - Migrated graph logic from [jekyll-namespaces](https://github.com/manunamz/jekyll-namespaces/) and [jekyll-wikilinks](https://github.com/manunamz/jekyll-wikilinks/) to this gem. 43 | - Added javascript scripts for cleaner user experience (simply insert a div and subclass the javascript class to get a graph up and running). 44 | ### Changed 45 | - Cleaned up testing 46 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | # Specify your gem's dependencies in jekyll-graph.gemspec 6 | gemspec 7 | 8 | gem "jekyll", "~> 4.2.0" 9 | gem "jekyll-namespaces", "~> 0.0.3" 10 | gem "jekyll-wikilinks", "~> 0.0.11" 11 | 12 | gem "rake", "~> 13.0.3" 13 | gem "rspec", "~> 3.10" 14 | gem "rubocop", "~> 1.14.0" 15 | 16 | gem "webrick", "~> 1.7" 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | 676 | https://choosealicense.com/licenses/gpl-3.0/ 677 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Jekyll-Graph 2 | 3 | [![A WikiBonsai Project](https://img.shields.io/badge/%F0%9F%8E%8B-A%20WikiBonsai%20Project-brightgreen)](https://github.com/wikibonsai/wikibonsai) 4 | [![Ruby Gem](https://img.shields.io/gem/v/jekyll-graph)](https://rubygems.org/gems/jekyll-graph) 5 | 6 | ⚠️ This is gem is under active development! ⚠️ 7 | 8 | ⚠️ Expect breaking changes and surprises until otherwise noted (likely by v0.1.0 or v1.0.0). ⚠️ 9 | 10 | Jekyll-Graph generates data and renders a graph that allows visitors to navigate a jekyll site by clicking nodes in the graph. Nodes are generated from the site's markdown files. Links for the tree graph are generated from [`jekyll-semtree`](https://github.com/wikibonsai/jekyll-semtree) and links for the web graph from [`jekyll-wikirefs`](https://github.com/wikibonsai/jekyll-wikirefs) (legacy versions from [`jekyll-namespaces`](https://github.com/manunamz/jekyll-namespaces) and [`jekyll-wikilinks`](https://github.com/manunamz/jekyll-wikilinks) respectively). 11 | 12 | 🏡 Build and maintain a treehouze to play in in your [WikiBonsai](https://github.com/wikibonsai/wikibonsai) digital garden. 13 | 14 | ## Installation 15 | 16 | Follow the instructions for installing a [jekyll plugin](https://jekyllrb.com/docs/plugins/installation/) for `jekyll-graph`. 17 | 18 | ## Usage 19 | 20 | 1. Add `{% jekyll_graph %}` to the site head: 21 | 22 | ```html 23 | 24 | 25 | ... 26 | 27 | {% jekyll_graph %} 28 | 29 | 30 | ``` 31 | 32 | 2. Add a graph div in your html where you want the graph to be rendered: 33 | 34 | ```html 35 |
36 | ``` 37 | 38 | 3. Subclass `JekyllGraph` class in javascript like so: 39 | 40 | ```javascript 41 | import JekyllGraph from './jekyll-graph.js'; 42 | 43 | class JekyllGraphSubClass extends JekyllGraph { 44 | 45 | constructor() { 46 | super(); 47 | // access graph with 'this.graph' 48 | // access graph div with 'this.graphDiv' 49 | } 50 | 51 | // ... 52 | } 53 | ``` 54 | 55 | The import should point to the `jekyll-graph.js` javascript file generated by the plugin. Unless otherwise configured (see `path` vars below), the `jekyll-graph.js` file will be generated into `_site/assets/js/`. The sample javascript snippet above is presumed to be generated into `_site/assets/js/` as well. 56 | 57 | 4. Create a class instance: 58 | 59 | ```javascript 60 | var graph = new JekyllGraphSubClass(); 61 | ``` 62 | 63 | 5. Call `drawWeb()` and/or `drawTree()` to actually draw the graph. You could do this simply on initialization or on a button click, etc. 64 | 65 | ```javascript 66 | // on page load 67 | (() => { 68 | graph.drawWeb(); 69 | }); 70 | 71 | // on button click 72 | this.graphBtn.addEventListener('click', () => { 73 | graph.drawTree(); 74 | }); 75 | ``` 76 | ## Configuration 77 | 78 | Default configs look like this: 79 | 80 | ```yaml 81 | graph: 82 | enabled: true 83 | exclude: [] 84 | path: 85 | assets: "/assets" 86 | scripts: "/assets/js" 87 | web: 88 | enabled: true 89 | exclude: 90 | attrs: false 91 | links: false 92 | force: 93 | charge: 94 | strength_x: 95 | x_val: 96 | strength_y: 97 | y_val: 98 | tree: 99 | enabled: true 100 | force: 101 | charge: 102 | strength_x: 103 | x_val: 104 | strength_y: 105 | y_val: 106 | ``` 107 | 108 | `enabled`: Turn off the plugin by setting to `false`. 109 | 110 | `exclude`: Exclude specific jekyll document types (`posts`, `pages`, `collection_items`). 111 | 112 | `path.assets`: An optional custom assets location for graph assets to generate into. Location is relative to the root of the generated `_site/` directory. 113 | 114 | `path.scripts`: An optional custom scripts location for the graph scripts to generate into. Location is relative to the assets location in the `_site/` directory (If `assets_path` is set, but `scripts_path` is not, the location will default to `_site//js/`). 115 | 116 | `web.exclude.attrs` and `web.exclude.links`: Determines whether wikilink attributes and/or links are added to the web graph from the link index. 117 | 118 | `tree.enabled` and `web.enabled`: Toggles on/off the `tree` and `web` graphs, respectively. Be sure to disable graphs that are not in use. 119 | 120 | `tree.force` and `web.force`: These are force variables from d3's simulation forces. You can check out the [docs for details](https://github.com/d3/d3-force#simulation_force). 121 | 122 | Force values will likely need to be played with depending on the div size and number of nodes. [jekyll-bonsai](https://manunamz.github.io/jekyll-bonsai/) currently uses these values: 123 | 124 | ```yaml 125 | graph: 126 | tree: 127 | dag_lvl_dist: 100 128 | force: 129 | charge: -100 130 | strength_x: 0.3 131 | x_val: 0.9 132 | strength_y: 0.1 133 | y_val: 0.9 134 | web: 135 | force: 136 | charge: -300 137 | strength_x: 0.3 138 | x_val: 0.75 139 | strength_y: 0.1 140 | y_val: 0.9 141 | ``` 142 | 143 | No configurations are strictly necessary for plugin defaults to work. 144 | 145 | ## Colors 146 | 147 | Graph colors are determined by css variables which may be defined like so -- any valid css color works (hex, rgba, etc.): 148 | 149 | ```CSS 150 | /* make sure color vars are attached to the root of the html document */ 151 | html { 152 | /* nodes */ 153 | /* glow */ 154 | --graph-node-current-glow: yellow; 155 | --graph-node-tagged-glow: green; 156 | --graph-node-visited-glow: blue; 157 | /* color */ 158 | --graph-node-stroke-color: grey; 159 | --graph-node-missing-color: transparent; 160 | --graph-node-unvisited-color: brown; 161 | --graph-node-visited-color: green; 162 | /* links */ 163 | --graph-link-color: brown; 164 | --graph-particles-color: grey; 165 | /* label text */ 166 | --graph-text-color: black; 167 | } 168 | ``` 169 | 170 | ## Data 171 | Graph data is generated in the following format: 172 | 173 | For the web graph, `graph-web.json`,`links` are built from `backlinks` and `attributed` metadata generated in `jekyll-wikilinks`: 174 | 175 | ```json 176 | // graph-web.json 177 | { 178 | "nodes": [ 179 | { 180 | "id": "", 181 | "url": "", // site.baseurl is handled for you here 182 | "label": "", 183 | "neighbors": { 184 | "nodes": [, ...], 185 | "links": [, ...], 186 | } 187 | }, 188 | ... 189 | ], 190 | "links": [ 191 | { 192 | "source": "", 193 | "target": "", 194 | }, 195 | ... 196 | ] 197 | } 198 | ``` 199 | 200 | For the tree graph, `graph-tree.json`, `links` are built from a tree data structure constructed in `jekyll-namespaces`: 201 | 202 | ```json 203 | // graph-tree.json 204 | { 205 | "nodes": [ 206 | { 207 | "id": "", 208 | "url": "", // site.baseurl wil be handled for you here 209 | "label": "", 210 | "lineage": { 211 | "nodes": [, ...], 212 | "links": [, ...], 213 | } 214 | }, 215 | ... 216 | ], 217 | "links": [ 218 | { 219 | "source": "", 220 | "target": "", 221 | }, 222 | ... 223 | ] 224 | } 225 | ``` 226 | 227 | Unless otherwise defined, both json files are generated into `_site/assets/`. 228 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "bundler/gem_tasks" 4 | require "rspec/core/rake_task" 5 | 6 | RSpec::Core::RakeTask.new(:spec) 7 | 8 | require "rubocop/rake_task" 9 | 10 | RuboCop::RakeTask.new 11 | 12 | task default: %i[spec rubocop] 13 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | require "bundler/setup" 5 | require "jekyll-graph" 6 | 7 | # You can add fixtures and/or initialization code here to make experimenting 8 | # with your gem easier. You can also use a different console, if you like. 9 | 10 | # (If you use this, don't forget to add pry to your Gemfile!) 11 | # require "pry" 12 | # Pry.start 13 | 14 | require "irb" 15 | IRB.start(__FILE__) 16 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -vx 5 | 6 | bundle install 7 | 8 | # Do any other automated setup that you need to do here 9 | -------------------------------------------------------------------------------- /jekyll-graph.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative "lib/jekyll-graph/version" 4 | 5 | Gem::Specification.new do |spec| 6 | spec.name = "jekyll-graph" 7 | spec.version = Jekyll::Graph::VERSION 8 | spec.authors = ["manunamz"] 9 | spec.email = ["manunamz@pm.me"] 10 | 11 | spec.summary = "Add d3 graph generation to jekyll." 12 | # spec.description = "TODO: Write a longer description or delete this line." 13 | spec.homepage = "https://github.com/manunamz/jekyll-graph" 14 | spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0") 15 | spec.licenses = ["GPL3"] 16 | 17 | # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'" 18 | 19 | spec.metadata["homepage_uri"] = spec.homepage 20 | spec.metadata["source_code_uri"] = "https://github.com/manunamz/jekyll-graph" 21 | spec.metadata["changelog_uri"] = "https://github.com/manunamz/jekyll-graph/blob/main/CHANGELOG.md" 22 | 23 | # Specify which files should be added to the gem when it is released. 24 | # The `git ls-files -z` loads the files in the RubyGem that have been added into git. 25 | spec.files = Dir.chdir(File.expand_path(__dir__)) do 26 | `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) } 27 | end 28 | spec.bindir = "exe" 29 | spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } 30 | spec.require_paths = ["lib"] 31 | 32 | # Uncomment to register a new dependency of your gem 33 | spec.add_dependency "jekyll", "~> 4.2.0" 34 | 35 | # For more information and examples about making a new gem, checkout our 36 | # guide at: https://bundler.io/guides/creating_gem.html 37 | end 38 | -------------------------------------------------------------------------------- /lib/jekyll-graph.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | require "jekyll" 3 | 4 | require_relative "jekyll-graph/patch/context" 5 | require_relative "jekyll-graph/patch/page" 6 | require_relative "jekyll-graph/version" 7 | 8 | # setup config 9 | require_relative "jekyll-graph/config" 10 | Jekyll::Hooks.register :site, :after_init do |site| 11 | # global '$graph_conf' to ensure that all local jekyll plugins 12 | # are reading from the same configuration with the same helper methods 13 | # (global var is not ideal, but is DRY) 14 | $graph_conf = Jekyll::Graph::PluginConfig.new(site.config) 15 | end 16 | 17 | require_relative "jekyll-graph/tags" 18 | Liquid::Template.register_tag "jekyll_graph", Jekyll::Graph::HeadTag 19 | Liquid::Template.register_tag "graph_scripts", Jekyll::Graph::GraphScriptTag 20 | 21 | module Jekyll 22 | module Graph 23 | 24 | class Generator < Jekyll::Generator 25 | priority :lowest 26 | 27 | # Use Jekyll's native relative_url filter 28 | include Jekyll::Filters::URLFilters 29 | 30 | CONVERTER_CLASS = Jekyll::Converters::Markdown 31 | 32 | def generate(site) 33 | # check what's enabled 34 | return if $graph_conf.disabled? 35 | # deprecated: 'net_web' -> 'web' 36 | if !$graph_conf.disabled_net_web? && !site.respond_to?(:link_index) 37 | Jekyll.logger.error("Jekyll-Graph: To generate the net-web graph, please either add and enable the 'jekyll-wikirefs' or 'jekyll-wikilinks' plugin or disable the net-web in the jekyll-graph config") 38 | return 39 | end 40 | if !$graph_conf.disabled_web? && !site.respond_to?(:link_index) 41 | Jekyll.logger.error("Jekyll-Graph: To generate the web graph, please either add and enable the 'jekyll-wikirefs' or 'jekyll-wikilinks' plugin or disable the web in the jekyll-graph config") 42 | return 43 | end 44 | if !$graph_conf.disabled_tree? && !site.respond_to?(:tree) 45 | Jekyll.logger.error("Jekyll-Graph: To generate the tree graph, please either add and enable the 'jekyll-semtree' or 'jekyll-namespaces' plugin, or disable the tree in the jekyll-graph config") 46 | return 47 | end 48 | 49 | # setup site 50 | @site = site 51 | @context ||= Context.new(site) 52 | 53 | # setup markdown docs 54 | docs = [] 55 | docs += @site.pages if !$graph_conf.excluded?(:pages) 56 | docs += @site.docs_to_write.filter { |d| !$graph_conf.excluded?(d.type) } 57 | @md_docs = docs.filter { |doc| markdown_extension?(doc.extname) } 58 | if @md_docs.empty? 59 | Jekyll.logger.warn("Jekyll-Graph: No documents to process.") 60 | end 61 | 62 | # write graph 63 | if !$graph_conf.disabled_net_web? 64 | # generate json data 65 | json_net_web_nodes, json_net_web_links = self.generate_json_net_web() 66 | self.set_neighbors(json_net_web_nodes, json_net_web_links) 67 | net_web_graph_content = JSON.dump( 68 | nodes: json_net_web_nodes, 69 | links: json_net_web_links, 70 | ) 71 | # create json file 72 | json_net_web_graph_file = self.new_page($graph_conf.path_assets, "graph-net-web.json", net_web_graph_content) 73 | end 74 | if !$graph_conf.disabled_web? 75 | # generate json data 76 | json_web_nodes, json_web_links = self.generate_json_net_web() 77 | self.set_neighbors(json_web_nodes, json_web_links) 78 | web_graph_content = JSON.dump( 79 | nodes: json_web_nodes, 80 | links: json_web_links, 81 | ) 82 | # create json file 83 | json_web_graph_file = self.new_page($graph_conf.path_assets, "graph-web.json", web_graph_content) 84 | end 85 | if !$graph_conf.disabled_tree? 86 | # generate json data 87 | json_tree_nodes, json_tree_links = self.generate_json_tree(@site.tree.root) 88 | self.set_lineage(json_tree_nodes, json_tree_links) 89 | tree_graph_content = JSON.dump( 90 | nodes: json_tree_nodes, 91 | links: json_tree_links, 92 | ) 93 | # create json file 94 | json_tree_graph_file = self.new_page($graph_conf.path_assets, "graph-tree.json", tree_graph_content) 95 | end 96 | # add graph drawing scripts 97 | script_filename = "jekyll-graph.js" 98 | graph_script_content = File.read(source_path(script_filename)) 99 | # create js file 100 | static_file = self.new_page($graph_conf.path_scripts, script_filename, graph_script_content) 101 | end 102 | 103 | # helpers 104 | 105 | # from: https://github.com/jekyll/jekyll-sitemap/blob/master/lib/jekyll/jekyll-sitemap.rb#L39 106 | def source_path(file) 107 | File.expand_path "jekyll-graph/#{file}", __dir__ 108 | end 109 | 110 | # Checks if a file already exists in the site source 111 | def file_exists?(file_path) 112 | @site.static_files.any? { |p| p.url == "/#{file_path}" } 113 | end 114 | 115 | def markdown_extension?(extension) 116 | markdown_converter.matches(extension) 117 | end 118 | 119 | def markdown_converter 120 | @markdown_converter ||= @site.find_converter_instance(CONVERTER_CLASS) 121 | end 122 | 123 | # generator helpers 124 | 125 | def new_page(path, filename, content) 126 | new_file = PageWithoutAFile.new(@site, __dir__, "", filename) 127 | new_file.content = content 128 | new_file.data["layout"] = nil 129 | new_file.data["permalink"] = File.join(path, filename) 130 | @site.pages << new_file unless file_exists?(filename) 131 | return new_file 132 | end 133 | 134 | # keeping this around in case it's needed again 135 | # # tests fail without manually adding the static file, but actual site builds seem to do ok 136 | # # ...although there does seem to be a race condition which causes a rebuild to be necessary in order to detect the graph data file 137 | # def register_static_file(static_file) 138 | # @site.static_files << static_file if !@site.static_files.include?(static_file) 139 | # end 140 | 141 | # json population helpers 142 | # set ids here, full javascript objects are populated in client-side javascript. 143 | 144 | def set_neighbors(json_nodes, json_links) 145 | json_links.each do |json_link| 146 | source_node = json_nodes.detect { |n| n[:id] == json_link[:source] } 147 | target_node = json_nodes.detect { |n| n[:id] == json_link[:target] } 148 | 149 | source_node[:neighbors][:nodes] << target_node[:id] 150 | target_node[:neighbors][:nodes] << source_node[:id] 151 | 152 | source_node[:neighbors][:links] << json_link 153 | target_node[:neighbors][:links] << json_link 154 | end 155 | end 156 | 157 | def set_lineage(json_nodes, json_links) 158 | # TODO: json nodes have relative_url, but node.id's/urls are doc urls. 159 | json_nodes.each do |json_node| 160 | # set lineage 161 | 162 | ancestor_node_ids, descendent_node_ids = @site.tree.get_all_lineage_ids(json_node[:id]) 163 | lineage_node_ids = ancestor_node_ids.concat(descendent_node_ids) 164 | json_node[:lineage][:nodes] = lineage_node_ids if !lineage_node_ids.nil? 165 | 166 | # include current node when filtering for links along entire relative lineage 167 | lineage_ids = lineage_node_ids.concat([json_node[:id]]) 168 | 169 | json_lineage_links = json_links.select { |l| lineage_ids.include?(l[:source]) && lineage_ids.include?(l[:target]) } 170 | json_node[:lineage][:links] = json_lineage_links if !json_lineage_links.nil? 171 | 172 | # set siblings 173 | 174 | json_node[:siblings] = @site.tree.get_sibling_ids(json_node[:id]) 175 | end 176 | end 177 | 178 | # json generation helpers 179 | 180 | # deprecated: 'net_web' -> 'web' 181 | def generate_json_net_web() 182 | return generate_json_web() 183 | end 184 | 185 | def generate_json_web() 186 | web_nodes, web_links = [], [] 187 | 188 | @md_docs.each do |doc| 189 | if !$graph_conf.excluded?(doc.type) 190 | 191 | Jekyll.logger.debug("Jekyll-Graph: Processing graph nodes for doc: ", doc.data['title']) 192 | # 193 | # missing nodes 194 | # 195 | @site.link_index.index[doc.url].missing.each do |missing_link_name| 196 | if web_nodes.none? { |node| node[:id] == missing_link_name } 197 | Jekyll.logger.warn("Jekyll-Graph: Net-Web node missing: #{missing_link_name}, in: #{File.basename(doc.basename, File.extname(doc.basename))}") 198 | web_nodes << { 199 | id: missing_link_name, # an id is necessary for link targets 200 | url: '', 201 | label: missing_link_name, 202 | neighbors: { 203 | nodes: [], 204 | links: [], 205 | }, 206 | } 207 | web_links << { 208 | source: doc.url, 209 | target: missing_link_name, 210 | } 211 | end 212 | end 213 | # 214 | # existing nodes 215 | # 216 | web_nodes << { 217 | # TODO: when using real ids, be sure to convert id to string (to_s) 218 | id: doc.url, 219 | url: relative_url(doc.url), 220 | label: doc.data['title'], 221 | neighbors: { 222 | nodes: [], 223 | links: [], 224 | }, 225 | } 226 | # TODO: this link calculation ends up with duplicates -- re-visit this later. 227 | if $graph_conf.use_attrs? 228 | @site.link_index.index[doc.url].attributes.each do |link| # link = { 'type' => str, 'urls' => [str, str, ...] } 229 | # TODO: Header + Block-level wikilinks 230 | link['urls'].each do |lu| 231 | link_no_anchor = lu.match(/([^#]+)/i)[0] 232 | link_no_baseurl = @site.baseurl.nil? ? link_no_anchor : link_no_anchor.gsub(@site.baseurl, "") 233 | linked_doc = @md_docs.select{ |d| d.url == link_no_baseurl } 234 | if !linked_doc.nil? && linked_doc.size == 1 && !$graph_conf.excluded?(linked_doc.first.type) 235 | # TODO: add link['type'] to d3 graph 236 | web_links << { 237 | source: doc.url, 238 | target: linked_doc.first.url, 239 | } 240 | end 241 | end 242 | end 243 | end 244 | if $graph_conf.use_links? 245 | @site.link_index.index[doc.url].forelinks.each do |link| # link = { 'type' => str, 'url' => str } 246 | # TODO: Header + Block-level wikilinks 247 | link_no_anchor = link['url'].match(/([^#]+)/i)[0] 248 | link_no_baseurl = @site.baseurl.nil? ? link_no_anchor : link_no_anchor.gsub(@site.baseurl, "") 249 | linked_doc = @md_docs.select{ |d| d.url == link_no_baseurl } 250 | if !linked_doc.nil? && linked_doc.size == 1 && !$graph_conf.excluded?(linked_doc.first.type) 251 | # TODO: add link['type'] to d3 graph 252 | web_links << { 253 | source: doc.url, 254 | target: linked_doc.first.url, 255 | } 256 | end 257 | end 258 | end 259 | 260 | end 261 | end 262 | 263 | return web_nodes, web_links 264 | end 265 | 266 | # used for both plugins: 267 | # jekyll-semtree 268 | # jekyll-namespace 269 | def generate_json_tree(node, json_parent="", tree_nodes=[], tree_links=[], level=0) 270 | node = node.is_a?(String) ? @site.tree.nodes.detect { |n| n.text == node } : node 271 | # 272 | # missing nodes 273 | # 274 | if node.missing 275 | missing_text = node.namespace ? node.namespace : node.text 276 | Jekyll.logger.warn("Jekyll-Graph: Tree node missing: ", missing_text) 277 | 278 | if node.namespace 279 | leaf = node.namespace.split('.').pop() 280 | end 281 | missing_node = { 282 | id: node.namespace ? node.namespace : node.text, 283 | label: node.namespace ? leaf.gsub('-', ' ') : node.text, 284 | url: "", 285 | level: level, 286 | lineage: { 287 | nodes: [], 288 | links: [], 289 | }, 290 | siblings: [], 291 | } 292 | if node.namespace 293 | missing_node['namespace'] = node.namespace 294 | end 295 | # non-root handling 296 | if !json_parent.empty? 297 | missing_node[:parent] = json_parent[:id] 298 | tree_links << { 299 | source: json_parent[:id], 300 | target: node.namespace ? node.namespace : node.text, 301 | } 302 | end 303 | tree_nodes << missing_node 304 | json_parent = missing_node 305 | # 306 | # existing nodes 307 | # 308 | else 309 | existing_node = { 310 | id: node.url, 311 | label: node.title, 312 | url: relative_url(node.url), 313 | level: level, 314 | lineage: { 315 | nodes: [], 316 | links: [], 317 | }, 318 | siblings: [], 319 | } 320 | if node.namespace 321 | existing_node['namespace'] = node.namespace 322 | end 323 | # non-root handling 324 | if !json_parent.empty? 325 | existing_node[:parent] = json_parent[:id] 326 | tree_links << { 327 | source: json_parent[:id], 328 | target: node.url, 329 | } 330 | end 331 | tree_nodes << existing_node 332 | json_parent = existing_node 333 | end 334 | node.children.each do |child| 335 | self.generate_json_tree(child, json_parent, tree_nodes, tree_links, (level + 1)) 336 | end 337 | return tree_nodes, tree_links 338 | end 339 | end 340 | 341 | end 342 | end 343 | -------------------------------------------------------------------------------- /lib/jekyll-graph/config.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | require "jekyll" 3 | 4 | module Jekyll 5 | module Graph 6 | 7 | class PluginConfig 8 | 9 | ASSETS_KEY = "assets" 10 | ATTRS_KEY = "attrs" 11 | CONFIG_KEY = "graph" 12 | ENABLED_KEY = "enabled" 13 | EXCLUDE_KEY = "exclude" 14 | LINKS_KEY = "links" 15 | NET_WEB_KEY = "net_web" # deprecated: 'net_web' -> 'web' 16 | PATH_KEY = "path" 17 | SCRIPTS_KEY = "scripts" 18 | TREE_KEY = "tree" 19 | WEB_KEY = "web" 20 | 21 | def initialize(config) 22 | @config ||= config 23 | @testing ||= config['testing'] if config.keys.include?('testing') 24 | Jekyll.logger.debug("Excluded jekyll types in graph: ", option(EXCLUDE_KEY)) unless disabled? 25 | end 26 | 27 | # descriptors 28 | 29 | def disabled? 30 | return option(ENABLED_KEY) == false 31 | end 32 | 33 | def disabled_tree? 34 | return option_tree(ENABLED_KEY) == false 35 | end 36 | 37 | # deprecated: 'net_web' -> 'web' 38 | def disabled_net_web? 39 | return option_web(ENABLED_KEY) == false 40 | end 41 | 42 | def disabled_web? 43 | option_web(ENABLED_KEY) == false 44 | end 45 | 46 | def excluded?(type) 47 | return false unless option(EXCLUDE_KEY) 48 | return option(EXCLUDE_KEY).include?(type.to_s) 49 | end 50 | 51 | def has_custom_assets_path? 52 | return option_path(ASSETS_KEY) 53 | end 54 | 55 | def has_custom_scripts_path? 56 | return option_path(SCRIPTS_KEY) 57 | end 58 | 59 | def use_attrs? 60 | return true if option_web_exclude(ATTRS_KEY).nil? 61 | return !option_web_exclude(ATTRS_KEY) 62 | end 63 | 64 | def use_links? 65 | return true if option_web_exclude(LINKS_KEY).nil? 66 | return !option_web_exclude(LINKS_KEY) 67 | end 68 | 69 | # options 70 | 71 | def option(key) 72 | @config[CONFIG_KEY] && @config[CONFIG_KEY][key] 73 | end 74 | 75 | def option_path(key) 76 | @config[CONFIG_KEY] && @config[CONFIG_KEY][PATH_KEY] && @config[CONFIG_KEY][PATH_KEY][key] 77 | end 78 | 79 | def option_web(key) 80 | if @config[CONFIG_KEY] 81 | # deprecated: 'net_web' -> 'web' 82 | if @config[CONFIG_KEY][NET_WEB_KEY] 83 | return @config[CONFIG_KEY][NET_WEB_KEY][key] 84 | end 85 | if @config[CONFIG_KEY][WEB_KEY] 86 | return @config[CONFIG_KEY][WEB_KEY][key] 87 | end 88 | end 89 | end 90 | 91 | def option_web_exclude(key) 92 | if @config[CONFIG_KEY] 93 | # deprecated: 'net_web' -> 'web' 94 | if @config[CONFIG_KEY][NET_WEB_KEY] && @config[CONFIG_KEY][NET_WEB_KEY][EXCLUDE_KEY] 95 | return @config[CONFIG_KEY][NET_WEB_KEY][EXCLUDE_KEY][key] 96 | end 97 | if @config[CONFIG_KEY][WEB_KEY]&& @config[CONFIG_KEY][WEB_KEY][EXCLUDE_KEY] 98 | return @config[CONFIG_KEY][WEB_KEY][EXCLUDE_KEY][key] 99 | end 100 | end 101 | end 102 | 103 | def option_tree(key) 104 | @config[CONFIG_KEY] && @config[CONFIG_KEY][TREE_KEY] && @config[CONFIG_KEY][TREE_KEY][key] 105 | end 106 | 107 | # attrs 108 | 109 | def baseurl 110 | return @config['baseurl'] 111 | end 112 | 113 | def path_assets 114 | return has_custom_assets_path? ? option_path(ASSETS_KEY) : "/assets" 115 | end 116 | 117 | def path_scripts 118 | return has_custom_scripts_path? ? File.join(path_assets, option_path(SCRIPTS_KEY)) : File.join(path_assets, "js") 119 | end 120 | 121 | def testing 122 | return @testing 123 | end 124 | end 125 | 126 | end 127 | end 128 | -------------------------------------------------------------------------------- /lib/jekyll-graph/jekyll-graph.js: -------------------------------------------------------------------------------- 1 | // don't need frontmatter because liquid is handled internally...somehow... 2 | 3 | export default class JekyllGraph { 4 | 5 | constructor() { 6 | this.graphDiv = document.getElementById('jekyll-graph'); 7 | } 8 | 9 | // d3 10 | 11 | // deprecated: 'net_web' -> 'web' 12 | drawNetWeb () { 13 | this.drawWeb(true); 14 | } 15 | 16 | drawWeb (legacy = false) { 17 | let assetsPath = '{{ site.graph.path.assets }}' !== '' ? '{{ site.graph.path.assets }}' : '/assets'; 18 | // deprecated: 'net-web' -> 'web' in filenames 19 | let filename = legacy ? 'graph-net-web.json' : 'graph-web.json'; 20 | fetch(`{{ site.baseurl }}${assetsPath}/${filename}`).then(res => res.json()).then(data => { 21 | 22 | // neighbors: replace ids with full object 23 | data.nodes.forEach(node => { 24 | let neighborNodes = []; 25 | node.neighbors.nodes.forEach(nodeId => { 26 | neighborNodes.push(data.nodes.find(node => node.id === nodeId)); 27 | }); 28 | let neighborLinks = []; 29 | node.neighbors.links.forEach(linkIds => { 30 | neighborLinks.push(data.links.find(link => link.source === linkIds.source && link.target === linkIds.target)); 31 | }); 32 | node.neighbors.nodes = neighborNodes; 33 | node.neighbors.links = neighborLinks; 34 | }); 35 | 36 | const highlightNodes = new Set(); 37 | const highlightLinks = new Set(); 38 | let hoverNode = null; 39 | let hoverLink = null; 40 | 41 | if (this.graph) { 42 | this.graph._destructor(); 43 | } 44 | 45 | // deprecated: 'net_web' -> 'web' in configs 46 | const charge = legacy ? '{{ site.graph.net_web.force.charge }}' : '{{ site.graph.web.force.charge }}'; 47 | const xStrength = legacy ? '{{ site.graph.net_web.force.strength_x }}' : '{{ site.graph.web.force.strength_x }}'; 48 | const xVal = legacy ? '{{ site.graph.net_web.force.x_val }}' : '{{ site.graph.web.force.x_val }}'; 49 | const yStrength = legacy ? '{{ site.graph.net_web.force.strength_y }}' : '{{ site.graph.web.force.strength_y }}'; 50 | const yVal = legacy ? '{{ site.graph.net_web.force.y_val }}' : '{{ site.graph.web.force.y_val }}'; 51 | 52 | const Graph = ForceGraph()(this.graphDiv) 53 | // container 54 | .height(this.graphDiv.parentElement.clientHeight) 55 | .width(this.graphDiv.parentElement.clientWidth) 56 | // node 57 | .nodeCanvasObject((node, ctx) => this.nodePaint(node, ctx, hoverNode, hoverLink, "web")) 58 | // .nodePointerAreaPaint((node, color, ctx, scale) => nodePaint(node, nodeTypeInWeb(node), ctx)) 59 | .nodeId('id') 60 | .nodeLabel('label') 61 | .onNodeClick((node, event) => this.goToPage(node, event)) 62 | // link 63 | .linkSource('source') 64 | .linkTarget('target') 65 | .linkColor(() => getComputedStyle(document.documentElement).getPropertyValue('--graph-link-color')) 66 | // forces 67 | // .d3Force('link', d3.forceLink() 68 | // .id(function(d) {return d.id;}) 69 | // .distance(30) 70 | // .iterations(1)) 71 | // .links(data.links)) 72 | 73 | .d3Force('charge', d3.forceManyBody() 74 | .strength(Number(charge))) 75 | // .d3Force('collide', d3.forceCollide()) 76 | // .d3Force('center', d3.forceCenter()) 77 | .d3Force('forceX', d3.forceX() 78 | .strength(Number(xStrength)) 79 | .x(Number(xVal))) 80 | .d3Force('forceY', d3.forceY() 81 | .strength(Number(yStrength)) 82 | .y(Number(yVal))) 83 | 84 | // hover 85 | .autoPauseRedraw(false) // keep redrawing after engine has stopped 86 | .onNodeHover(node => { 87 | highlightNodes.clear(); 88 | highlightLinks.clear(); 89 | if (node) { 90 | highlightNodes.add(node); 91 | node.neighbors.nodes.forEach(node => highlightNodes.add(node)); 92 | node.neighbors.links.forEach(link => highlightLinks.add(link)); 93 | } 94 | hoverNode = node || null; 95 | }) 96 | .onLinkHover(link => { 97 | highlightNodes.clear(); 98 | highlightLinks.clear(); 99 | if (link) { 100 | highlightLinks.add(link); 101 | highlightNodes.add(link.source); 102 | highlightNodes.add(link.target); 103 | } 104 | hoverLink = link || null; 105 | }) 106 | .linkDirectionalParticles(4) 107 | .linkDirectionalParticleWidth(link => highlightLinks.has(link) ? 2 : 0) 108 | .linkDirectionalParticleColor(() => getComputedStyle(document.documentElement).getPropertyValue('--graph-particles-color')) 109 | // zoom 110 | // (fit to canvas when engine stops) 111 | // .onEngineStop(() => Graph.zoomToFit(400)) 112 | // data 113 | .graphData(data); 114 | 115 | elementResizeDetectorMaker().listenTo( 116 | this.graphDiv, 117 | function(el) { 118 | Graph.width(el.offsetWidth); 119 | Graph.height(el.offsetHeight); 120 | } 121 | ); 122 | 123 | this.graph = Graph; 124 | }); 125 | } 126 | 127 | drawTree () { 128 | let assetsPath = '{{ site.graph.path.assets }}' !== '' ? '{{ site.graph.path.assets }}' : '/assets'; 129 | fetch(`{{ site.baseurl }}${assetsPath}/graph-tree.json`).then(res => res.json()).then(data => { 130 | 131 | if (this.graph) { 132 | this.graph._destructor(); 133 | } 134 | 135 | // node height vars 136 | this.shifted = []; 137 | this.numSiblingsLeft = []; 138 | 139 | // hover vars 140 | const highlightNodes = new Set(); 141 | const highlightLinks = new Set(); 142 | let hoverNode = null; 143 | let hoverLink = null; 144 | 145 | // lineage: replace ids with full objects 146 | data.nodes.forEach(node => { 147 | // lineage 148 | let lineageNodes = []; 149 | node.lineage.nodes.forEach(nodeId => { 150 | lineageNodes.push(data.nodes.find(node => node.id === nodeId)); 151 | }); 152 | let lineageLinks = []; 153 | node.lineage.links.forEach(linkIds => { 154 | lineageLinks.push(data.links.find(link => link.source === linkIds.source && link.target === linkIds.target)); 155 | }); 156 | node.lineage.nodes = lineageNodes; 157 | node.lineage.links = lineageLinks; 158 | // siblings 159 | this.numSiblingsLeft[node.parent] = node.siblings.length; 160 | }); 161 | 162 | const Graph = ForceGraph()(this.graphDiv) 163 | // dag-mode (tree) 164 | .dagMode('td') 165 | .dagLevelDistance(Number('{{ site.graph.tree.dag_lvl_dist }}')) 166 | // container 167 | .height(this.graphDiv.parentElement.clientHeight) 168 | .width(this.graphDiv.parentElement.clientWidth) 169 | // node 170 | .nodeCanvasObject((node, ctx) => this.nodePaint(node, ctx, hoverNode, hoverLink, "tree")) 171 | // .nodePointerAreaPaint((node, color, ctx, scale) => nodePaint(node, nodeTypeInWeb(node), ctx)) 172 | .nodeId('id') 173 | .nodeLabel('label') 174 | // todo-shift: this shiftNodeHeight() always renders, but animatation is choppy 175 | // .nodeVal(node => this.shiftNodeHeight(node)) 176 | .onNodeClick((node, event) => this.goToPage(node, event)) 177 | // link 178 | .linkSource('source') 179 | .linkTarget('target') 180 | .linkColor(() => getComputedStyle(document.documentElement).getPropertyValue('--graph-link-color')) 181 | // forces 182 | // .d3Force('link', d3.forceLink() 183 | // .id(function(d) {return d.id;}) 184 | // .distance(30) 185 | // .iterations(1)) 186 | // .links(data.links)) 187 | 188 | .d3Force('charge', d3.forceManyBody() 189 | .strength(Number('{{ site.graph.tree.force.charge }}'))) 190 | // .d3Force('collide', d3.forceCollide()) 191 | // .d3Force('center', d3.forceCenter()) 192 | .d3Force('forceX', d3.forceX() 193 | .strength(Number('{{ site.graph.tree.force.strength_x }}')) 194 | .x(Number('{{ site.graph.tree.force.x_val }}'))) 195 | .d3Force('forceY', d3.forceY() 196 | .strength(Number('{{ site.graph.tree.force.strength_y }}')) 197 | .y(Number('{{ site.graph.tree.force.y_val }}'))) 198 | 199 | // hover 200 | .autoPauseRedraw(false) // keep redrawing after engine has stopped 201 | .onNodeHover(node => { 202 | highlightNodes.clear(); 203 | highlightLinks.clear(); 204 | if (node) { 205 | highlightNodes.add(node); 206 | node.lineage.nodes.forEach(node => highlightNodes.add(node)); 207 | node.lineage.links.forEach(link => highlightLinks.add(link)); 208 | } 209 | hoverNode = node || null; 210 | }) 211 | .onLinkHover(link => { 212 | highlightNodes.clear(); 213 | highlightLinks.clear(); 214 | if (link) { 215 | highlightLinks.add(link); 216 | highlightNodes.add(link.source); 217 | highlightNodes.add(link.target); 218 | } 219 | hoverLink = link || null; 220 | }) 221 | .linkDirectionalParticles(4) 222 | .linkDirectionalParticleWidth(link => highlightLinks.has(link) ? 2 : 0) 223 | .linkDirectionalParticleColor(() => getComputedStyle(document.documentElement).getPropertyValue('--graph-particles-color')) 224 | // zoom 225 | // (fit to canvas when engine stops) 226 | // .onEngineStop(() => Graph.zoomToFit(400)) 227 | // data 228 | .graphData(data); 229 | 230 | elementResizeDetectorMaker().listenTo( 231 | this.graphDiv, 232 | function(el) { 233 | Graph.width(el.offsetWidth); 234 | Graph.height(el.offsetHeight); 235 | } 236 | ); 237 | 238 | this.graph = Graph; 239 | }); 240 | } 241 | 242 | // draw helpers 243 | 244 | // shiftNodeHeight(node) { 245 | // if ((node.namespace !== 'root') && (node.namespace !== 'i.bonsai') && !this.shifted.includes(node)) { 246 | // const padding = 5; 247 | // let areSiblingsLeftEven = (this.numSiblingsLeft[node.parent] % 2) === 1; 248 | // let altrntr = areSiblingsLeftEven ? 1 : -1; 249 | // node.fy = node.fy + (altrntr * (this.numSiblingsLeft[node.parent] * padding)); 250 | // this.numSiblingsLeft[node.parent] -= 1; 251 | // this.shifted.push(node); 252 | // } 253 | // } 254 | 255 | nodePaint(node, ctx, hoverNode, hoverLink, gType) { 256 | // todo-shift: this shiftNodeHeight() animates more smoothly, but suffers from a race condition 257 | // if (gType === "tree") { 258 | // this.shiftNodeHeight(node); 259 | // } 260 | let fillText = true; 261 | let radius = 6; 262 | // 263 | // nodes color 264 | // 265 | if (this.isVisitedPage(node)) { 266 | ctx.fillStyle = getComputedStyle(document.documentElement).getPropertyValue('--graph-node-visited-color'); 267 | } else if (this.isMissingPage(node)) { 268 | ctx.fillStyle = getComputedStyle(document.documentElement).getPropertyValue('--graph-node-missing-color'); 269 | } else if (!this.isVisitedPage(node) && !this.isMissingPage(node)) { 270 | ctx.fillStyle = getComputedStyle(document.documentElement).getPropertyValue('--graph-node-unvisited-color'); 271 | } else { 272 | console.log("WARN: Not a valid base node type."); 273 | } 274 | ctx.beginPath(); 275 | // 276 | // hover behavior 277 | // 278 | if (node === hoverNode) { 279 | // hoverNode 280 | radius *= 2; 281 | fillText = false; // node label should be active 282 | } else if (hoverNode !== null && gType === "web" && hoverNode.neighbors.nodes.includes(node)) { 283 | // neighbor to hoverNode 284 | } else if (hoverNode !== null && gType === "web" && !hoverNode.neighbors.nodes.includes(node)) { 285 | // non-neighbor to hoverNode 286 | fillText = false; 287 | } else if (hoverNode !== null && gType === "tree" && hoverNode.lineage.nodes.includes(node)) { 288 | // neighbor to hoverNode 289 | } else if (hoverNode !== null && gType === "tree" && !hoverNode.lineage.nodes.includes(node)) { 290 | // non-neighbor to hoverNode 291 | fillText = false; 292 | } else if ((hoverNode === null && hoverLink !== null) && (hoverLink.source === node || hoverLink.target === node)) { 293 | // neighbor to hoverLink 294 | fillText = true; 295 | } else if ((hoverNode === null && hoverLink !== null) && (hoverLink.source !== node && hoverLink.target !== node)) { 296 | // non-neighbor to hoverLink 297 | fillText = false; 298 | } else { 299 | // no hover (default) 300 | } 301 | ctx.arc(node.x, node.y, radius, 0, 2 * Math.PI, false); 302 | // 303 | // glow behavior 304 | // 305 | if (this.isCurrentPage(node)) { 306 | // turn glow on 307 | ctx.shadowBlur = 40; 308 | ctx.shadowColor = getComputedStyle(document.documentElement).getPropertyValue('--graph-node-current-glow'); 309 | } else if (this.isTag(node)) { 310 | // turn glow on 311 | ctx.shadowBlur = 40; 312 | ctx.shadowColor = getComputedStyle(document.documentElement).getPropertyValue('--graph-node-tagged-glow'); 313 | } else if (this.isVisitedPage(node)) { 314 | // turn glow on 315 | ctx.shadowBlur = 20; 316 | ctx.shadowColor = getComputedStyle(document.documentElement).getPropertyValue('--graph-node-visited-glow'); 317 | } else { 318 | // no glow 319 | } 320 | ctx.fill(); 321 | // turn glow off 322 | ctx.shadowBlur = 0; 323 | ctx.shadowColor = ""; 324 | // 325 | // draw node borders 326 | // 327 | ctx.lineWidth = radius * (2 / 5); 328 | ctx.strokeStyle = getComputedStyle(document.documentElement).getPropertyValue('--graph-node-stroke-color'); 329 | ctx.stroke(); 330 | // 331 | // node labels 332 | // 333 | if (fillText) { 334 | // add peripheral node text 335 | ctx.fillStyle = getComputedStyle(document.documentElement).getPropertyValue('--graph-text-color'); 336 | ctx.fillText(node.label, node.x + radius + 1, node.y + radius + 1); 337 | } 338 | } 339 | 340 | isCurrentPage(node) { 341 | return !this.isMissingPage(node) && window.location.pathname.includes(node.url); 342 | } 343 | 344 | isTag(node) { 345 | // if (!isPostPage) return false; 346 | const semTags = Array.from(document.getElementsByClassName("sem-tag")); 347 | const tagged = semTags.filter((semTag) => 348 | !this.isMissingPage(node) && semTag.hasAttribute("href") && semTag.href.includes(node.url) 349 | ); 350 | return tagged.length !== 0; 351 | } 352 | 353 | isVisitedPage(node) { 354 | if (!this.isMissingPage(node)) { 355 | var visited = JSON.parse(localStorage.getItem('visited')); 356 | if (visited !== null) { 357 | for (let i = 0; i < visited.length; i++) { 358 | if (visited[i]['url'] === node.url) return true; 359 | } 360 | } 361 | } 362 | return false; 363 | } 364 | 365 | isMissingPage(node) { 366 | return node.url === ''; 367 | } 368 | 369 | // user-actions 370 | 371 | // from: https://stackoverflow.com/questions/63693132/unable-to-get-node-datum-on-mouseover-in-d3-v6 372 | // d3v6 now passes events in vanilla javascript fashion 373 | goToPage(node, e) { 374 | if (!this.isMissingPage(node)) { 375 | window.location.href = node.url; 376 | return true; 377 | } else { 378 | return false; 379 | } 380 | } 381 | } 382 | -------------------------------------------------------------------------------- /lib/jekyll-graph/patch/context.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class Context 4 | attr_reader :site 5 | 6 | def initialize(site) 7 | @site = site 8 | end 9 | 10 | def registers 11 | { :site => site } 12 | end 13 | end -------------------------------------------------------------------------------- /lib/jekyll-graph/patch/page.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | require "jekyll" 3 | 4 | module Jekyll 5 | module Graph 6 | 7 | class PageWithoutAFile < Page 8 | # rubocop:disable Naming/MemoizedInstanceVariableName 9 | def read_yaml(*) 10 | @data ||= {} 11 | end 12 | # rubocop:enable Naming/MemoizedInstanceVariableName 13 | end 14 | 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/jekyll-graph/tags.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Jekyll 4 | module Graph 5 | 6 | class HeadTag < Liquid::Tag 7 | def render(context) 8 | [ 9 | "", 10 | "", 11 | "", 12 | ].join("\n").gsub!("\n", "") # for long-string legibility 13 | end 14 | end 15 | 16 | # from: https://github.com/jekyll/jekyll-feed/blob/6d4913fe5017c685d2437f328ab4a9138cea07a8/lib/jekyll-feed/meta-tag.rb 17 | class GraphScriptTag < Liquid::Tag 18 | # TODO: this tag is actually not being used right now -- 19 | # but it's still here in case it is desirable to 20 | # allow users to access each graph via their own 21 | # div and skip scripting entirely 22 | 23 | # Use Jekyll's native relative_url filter 24 | include Jekyll::Filters::URLFilters 25 | 26 | def render(context) 27 | @context = context 28 | "" 29 | end 30 | end 31 | 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/jekyll-graph/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Jekyll 4 | module Graph 5 | 6 | VERSION = "0.0.11" 7 | 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /spec/fixtures/_docs_net_web/blank.a.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Blank A 3 | --- 4 | -------------------------------------------------------------------------------- /spec/fixtures/_docs_net_web/link.block.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Block Single Link 3 | --- 4 | This doc contains a wikilink to a block... 5 | 6 | block-single::[[blank.a]] 7 | 8 | ...link. 9 | -------------------------------------------------------------------------------- /spec/fixtures/_docs_net_web/link.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Untyped Link 3 | --- 4 | This doc contains a wikilink to [[blank.a]]. 5 | -------------------------------------------------------------------------------- /spec/fixtures/_docs_net_web/link.missing-doc.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Untyped Link Missing Doc 3 | --- 4 | This doc contains a wikilink to [[missing.doc]]. 5 | -------------------------------------------------------------------------------- /spec/fixtures/_docs_tree/blank.missing-lvl.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: bb89b5b9fd 3 | title: Missing Level 4 | --- 5 | 6 | This document contains a missing level in the namespace tree. 7 | -------------------------------------------------------------------------------- /spec/fixtures/_docs_tree/root.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: 595bac708b 3 | title: Root 4 | --- 5 | 6 | This is the root document. 7 | -------------------------------------------------------------------------------- /spec/fixtures/_docs_tree/second-level.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: ee0d5f8138 3 | title: Root Second Level 4 | --- 5 | 6 | This is a document with a filename with a second level. 7 | -------------------------------------------------------------------------------- /spec/fixtures/_docs_tree/second-level.third-level.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: 001ace2357 3 | title: Root Third Level 4 | --- 5 | 6 | This is a document with a filename with a second and third level. 7 | -------------------------------------------------------------------------------- /spec/fixtures/_docs_web/blank.a.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Blank A 3 | --- 4 | -------------------------------------------------------------------------------- /spec/fixtures/_docs_web/link.block.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Block Single Link 3 | --- 4 | This doc contains a wikilink to a block... 5 | 6 | block-single::[[blank.a]] 7 | 8 | ...link. 9 | -------------------------------------------------------------------------------- /spec/fixtures/_docs_web/link.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Untyped Link 3 | --- 4 | This doc contains a wikilink to [[blank.a]]. 5 | -------------------------------------------------------------------------------- /spec/fixtures/_docs_web/link.missing-doc.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Untyped Link Missing Doc 3 | --- 4 | This doc contains a wikilink to [[missing.doc]]. 5 | -------------------------------------------------------------------------------- /spec/fixtures/_posts/2020-12-08-one-post.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: One Post 3 | --- 4 | 5 | Posts support links, like to [[blank.a]]. 6 | -------------------------------------------------------------------------------- /spec/fixtures/assets/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wikibonsai/jekyll-graph/d927b45852db45d33aae6e860749d3dec7f69833/spec/fixtures/assets/image.png -------------------------------------------------------------------------------- /spec/fixtures/one-page.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: One Page 3 | --- 4 | 5 | This page links to a [[blank.a]]. 6 | -------------------------------------------------------------------------------- /spec/jekyll-graph/feature_basic_default_namespaces_tree_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "spec_helper" 4 | 5 | RSpec.describe(Jekyll::Graph::Generator) do 6 | let(:config) do 7 | Jekyll.configuration( 8 | config_overrides.merge( 9 | "collections" => { "docs_tree" => { "output" => true } }, 10 | "permalink" => "pretty", 11 | "skip_config_files" => false, 12 | "source" => fixtures_dir, 13 | "destination" => site_dir, 14 | "url" => "garden.testsite.com", 15 | "testing" => true, 16 | # "baseurl" => "", 17 | "wikilinks" => { "enabled" => false }, 18 | ) 19 | ) 20 | end 21 | # set configs to only test the tree graph 22 | let(:config_overrides) { { 23 | "namespaces" => { "exclude" => [ "docs_net_web" ] }, 24 | "graph" => { "net_web" => { "enabled" => false } } 25 | } } 26 | let(:site) { Jekyll::Site.new(config) } 27 | 28 | let(:doc_root) { find_by_title(site.collections["docs_tree"].docs, "Root") } 29 | let(:doc_second_lvl) { find_by_title(site.collections["docs_tree"].docs, "Root Second Level") } 30 | let(:doc_missing_lvl) { find_by_title(site.collections["docs_tree"].docs, "Missing Level") } 31 | 32 | let(:graph_data) { static_graph_file_content("tree") } 33 | let(:graph_generated_fpath) { find_generated_file("/assets/graph-tree.json") } 34 | let(:graph_root) { get_graph_root() } 35 | let(:graph_link) { get_graph_link_match_source("tree") } 36 | let(:graph_node) { get_graph_node("tree") } 37 | let(:missing_graph_node) { get_missing_graph_node() } 38 | 39 | # makes markdown tests work 40 | subject { described_class.new(site.config) } 41 | 42 | before(:each) do 43 | site.reset 44 | site.process 45 | end 46 | 47 | after(:each) do 48 | # cleanup _site/ dir 49 | FileUtils.rm_rf(Dir["#{site_dir()}"]) 50 | end 51 | 52 | context "GRAPH TYPE: TREE" do 53 | 54 | context "dependencies" do 55 | 56 | context "if 'tree' is enabled, but 'jekyll-namespaces' not enabled (or installed)" do 57 | let(:config_overrides) { { "namespaces" => { "enabled" => false } } } 58 | pending("todo: this is hard to test because i need to somehow mock the lack of plugin installation") 59 | 60 | # it "throw error if jekyll-namespaces' 'tree' is missing" do 61 | # expect { Jekyll.logger.error }.to raise_error(ArgumentError) 62 | # end 63 | 64 | end 65 | 66 | end 67 | 68 | context "when doc for tree.path level exists" do 69 | 70 | it "generates graph data" do 71 | expect(graph_generated_fpath).to eq(File.join(site_dir, "/assets/graph-tree.json")) 72 | expect(graph_data.class).to be(Hash) 73 | end 74 | 75 | context "json node" do 76 | 77 | it "has format: { nodes: [ {id: '', url: '', label: ''}, ... ] }" do 78 | expect(graph_node.keys).to include("id") 79 | expect(graph_node.keys).to include("url") 80 | expect(graph_node.keys).to include("label") 81 | end 82 | 83 | it "'id's equal their url (since urls should be unique)" do 84 | expect(graph_root["id"]).to eq(graph_root["url"]) 85 | end 86 | 87 | it "'label's equal their doc title" do 88 | expect(graph_root["label"]).to eq(doc_root.data["title"]) 89 | end 90 | 91 | it "root 'namespace's equal their doc filename" do 92 | expect(graph_root["namespace"]).to eq(doc_root.basename_without_ext) 93 | end 94 | 95 | it "non-root 'namespace's equal their doc filename with the 'root.' prefix" do 96 | expect(graph_node["namespace"]).to eq("root." + doc_second_lvl.basename_without_ext) 97 | end 98 | 99 | it "'url's equal their doc urls" do 100 | expect(graph_root["url"]).to eq(doc_root.url) 101 | end 102 | 103 | it "'lineage' is an object with keys 'nodes' and 'links'" do 104 | expect(graph_root["lineage"]).to be_a(Object) 105 | expect(graph_root["lineage"].keys).to eq(["nodes", "links"]) 106 | end 107 | 108 | it "'lineage' 'node' is an array of 'id's" do 109 | expect(graph_root["lineage"]["nodes"]).to be_a(Array) 110 | expect(graph_root["lineage"]["nodes"][0]).to be_a(String) 111 | expect(graph_root["lineage"]["nodes"]).to eq([ 112 | "/one-page/", 113 | "/2020/12/08/one-post/", 114 | "root.blank", 115 | "/docs_tree/blank.missing-lvl/", 116 | "/docs_tree/second-level/", 117 | "/docs_tree/second-level.third-level/", 118 | "/docs_tree/root/" 119 | ]) 120 | end 121 | 122 | it "'lineage' 'link' is an array of objects with 'source' and 'target' keys which are node ids" do 123 | expect(graph_root["lineage"]["links"]).to be_a(Array) 124 | expect(graph_root["lineage"]["links"][0].keys).to eq(["source", "target"]) 125 | expect(graph_root["lineage"]["links"]).to eq([ 126 | {"source"=>"/docs_tree/root/", "target"=>"/one-page/"}, 127 | {"source"=>"/docs_tree/root/", "target"=>"/2020/12/08/one-post/"}, 128 | {"source"=>"/docs_tree/root/", "target"=>"root.blank"}, 129 | {"source"=>"root.blank", "target"=>"/docs_tree/blank.missing-lvl/"}, 130 | {"source"=>"/docs_tree/root/", "target"=>"/docs_tree/second-level/"}, 131 | {"source"=>"/docs_tree/second-level/", "target"=>"/docs_tree/second-level.third-level/"} 132 | ]) 133 | end 134 | 135 | end 136 | 137 | context "json link" do 138 | 139 | it "has format: { links: [ { source: '', target: '', label: ''}, ... ] }" do 140 | expect(graph_link.keys).to include("source") 141 | expect(graph_link.keys).to include("target") 142 | end 143 | 144 | it "'source' equals the parent id" do 145 | expect(graph_link["source"]).to eq(graph_root["id"]) 146 | expect(graph_root["id"]).to eq("/docs_tree/root/") 147 | end 148 | 149 | it "'target' equals the child id" do 150 | expect(graph_link["target"]).to eq(graph_node["id"]) 151 | expect(graph_node["id"]).to eq("/docs_tree/second-level/") 152 | end 153 | 154 | end 155 | 156 | end 157 | 158 | context "when doc for tree.path level does not exist" do 159 | 160 | it "generates graph data" do 161 | expect(graph_generated_fpath).to eq(File.join(site_dir, "/assets/graph-tree.json")) 162 | expect(graph_data.class).to be(Hash) 163 | end 164 | 165 | context "parent of missing node" do 166 | 167 | it "has namespace of missing level in its child metadata" do 168 | expect(doc_root["children"]).to include("root.blank") 169 | end 170 | 171 | end 172 | 173 | context "missing node" do 174 | 175 | it "has keys: [ 'id', 'label', 'namespace', and 'url' ]" do 176 | expect(missing_graph_node.keys).to include("id") 177 | expect(missing_graph_node.keys).to include("label") 178 | expect(missing_graph_node.keys).to include("namespace") 179 | expect(missing_graph_node.keys).to include("url") 180 | end 181 | 182 | it "'id's equals its namespace" do 183 | expect(missing_graph_node["id"]).to eq(missing_graph_node["namespace"]) 184 | end 185 | 186 | it "'label' equals the namespace of the missing level" do 187 | expect(missing_graph_node["label"]).to eq("blank") 188 | end 189 | 190 | it "'url' is an empty string" do 191 | expect(missing_graph_node["url"]).to eq("") 192 | end 193 | 194 | end 195 | 196 | end 197 | 198 | end 199 | 200 | end 201 | -------------------------------------------------------------------------------- /spec/jekyll-graph/feature_basic_default_net_web_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # deprecated: 'net_web' -> 'web' 4 | 5 | require "spec_helper" 6 | 7 | RSpec.describe(Jekyll::Graph::Generator) do 8 | let(:config) do 9 | Jekyll.configuration( 10 | config_overrides.merge( 11 | "collections" => { "docs_net_web" => { "output" => true } }, 12 | "permalink" => "pretty", 13 | "skip_config_files" => false, 14 | "source" => fixtures_dir, 15 | "destination" => site_dir, 16 | "url" => "garden.testsite.com", 17 | "testing" => true, 18 | # "baseurl" => "", 19 | "namespaces" => { "enabled" => false }, 20 | ) 21 | ) 22 | end 23 | # set configs to only test the net-web graph 24 | let(:config_overrides) { { 25 | "wikilinks" => { "exclude" => [ "docs_tree" ] }, 26 | "graph" => { "tree" => { "enabled" => false } }, 27 | } } 28 | let(:site) { Jekyll::Site.new(config) } 29 | 30 | let(:untyped_link_doc) { find_by_title(site.collections["docs_net_web"].docs, "Untyped Link") } 31 | let(:blank_a) { find_by_title(site.collections["docs_net_web"].docs, "Base Case A") } 32 | let(:missing_doc) { find_by_title(site.collections["docs_net_web"].docs, "Untyped Link Missing Doc") } 33 | 34 | let(:graph_data) { static_graph_file_content("net-web") } 35 | let(:graph_generated_fpath) { find_generated_file("/assets/graph-net-web.json") } 36 | let(:graph_node) { get_graph_node("net-web") } 37 | let(:graph_link) { get_graph_link_match_source("net-web") } 38 | # deprecated: 'net-web' -> 'web' 39 | let(:missing_link_graph_node) { get_missing_link_graph_node(legacy=true) } 40 | let(:missing_target_graph_link) { get_missing_target_graph_link(legacy=true) } 41 | 42 | # makes markdown tests work 43 | subject { described_class.new(site.config) } 44 | 45 | before(:each) do 46 | site.reset 47 | site.process 48 | end 49 | 50 | after(:each) do 51 | # cleanup _site/ dir 52 | FileUtils.rm_rf(Dir["#{site_dir()}"]) 53 | end 54 | 55 | context "GRAPH TYPE: NET-WEB" do 56 | 57 | context "dependencies" do 58 | 59 | context "require site object has 'link_index' attribute (because jekyll-wikilinks was not enabled/installed)" do 60 | let(:config_overrides) { { "wikilinks" => { "enabled" => false } } } 61 | pending("todo: this is hard to test because i need to somehow mock the lack of plugin installation") 62 | 63 | # it "throw error if jekyll-wikilinks' 'link_index' is missing" do 64 | # expect { Jekyll.logger.error }.to raise_error 65 | # end 66 | 67 | end 68 | 69 | end 70 | 71 | context "when target [[wikilink]] doc exists" do 72 | 73 | it "generates graph data" do 74 | expect(graph_generated_fpath).to eq(File.join(site_dir, "/assets/graph-net-web.json")) 75 | expect(graph_data.class).to be(Hash) 76 | end 77 | 78 | context "node" do 79 | 80 | it "keys include 'id' 'url' 'label'" do 81 | expect(graph_node.keys).to include("id") 82 | expect(graph_node.keys).to include("url") 83 | expect(graph_node.keys).to include("label") 84 | end 85 | 86 | it "'id' equals their url (since urls should be unique)" do 87 | expect(graph_node["id"]).to eq(graph_node["url"]) 88 | end 89 | 90 | it "'label' equals their doc title" do 91 | expect(graph_node["label"]).to eq(untyped_link_doc.data["title"]) 92 | end 93 | 94 | it "'url's equal their doc urls" do 95 | expect(graph_node["url"]).to eq(untyped_link_doc.url) 96 | end 97 | 98 | it "'neighbors' is an object with keys 'nodes' and 'links'" do 99 | expect(graph_node["neighbors"]).to be_a(Object) 100 | expect(graph_node["neighbors"].keys).to eq(["nodes", "links"]) 101 | end 102 | 103 | it "'neighbors' 'node' is an id" do 104 | expect(graph_node["neighbors"]["nodes"]).to be_a(Array) 105 | expect(graph_node["neighbors"]["nodes"]).to eq([ 106 | "/docs_net_web/blank.a/", 107 | ]) 108 | end 109 | 110 | it "'neighbors' 'link' is an object with 'source' and 'target', which are node ids" do 111 | expect(graph_node["neighbors"]["links"]).to be_a(Array) 112 | expect(graph_node["neighbors"]["links"]).to eq([ 113 | {"source"=>"/docs_net_web/link/", "target"=>"/docs_net_web/blank.a/"}, 114 | ]) 115 | end 116 | 117 | end 118 | 119 | context "link" do 120 | 121 | it "contains keys 'source' and 'target'" do 122 | expect(graph_link.keys).to eq(["source", "target"]) 123 | end 124 | 125 | it "'source' and 'target' attributes equal some nodes' id" do 126 | expect(graph_link["source"]).to eq(graph_node["id"]) 127 | expect(graph_link["target"]).to eq("/docs_net_web/blank.a/") 128 | end 129 | 130 | end 131 | 132 | end 133 | 134 | context "when target [[wikilink]] doc does not exist" do 135 | 136 | it "generates graph data" do 137 | expect(graph_generated_fpath).to eq(File.join(site_dir, "/assets/graph-net-web.json")) 138 | expect(graph_data.class).to be(Hash) 139 | end 140 | 141 | context "node" do 142 | 143 | it "keys include 'id', 'url', and 'label'" do 144 | expect(missing_link_graph_node.keys).to include("id") 145 | expect(missing_link_graph_node.keys).to include("url") 146 | expect(missing_link_graph_node.keys).to include("label") 147 | end 148 | 149 | it "'id's equal the original [[wikitext]]" do 150 | expect(missing_link_graph_node["id"]).to eq("missing.doc") 151 | end 152 | 153 | it "'label's equal the original [[wikitext]]" do 154 | expect(missing_link_graph_node["label"]).to eq("missing.doc") 155 | end 156 | 157 | it "'url's are empty strings" do 158 | expect(missing_link_graph_node["url"]).to eq("") 159 | end 160 | 161 | end 162 | 163 | context "link" do 164 | 165 | it "contains keys 'source' and 'target'" do 166 | expect(missing_target_graph_link.keys).to eq(["source", "target"]) 167 | end 168 | 169 | it "missing 'target' equals the [[wikitext]] in brackets." do 170 | expect(missing_target_graph_link["target"]).to eq("missing.doc") 171 | end 172 | 173 | end 174 | 175 | end 176 | 177 | end 178 | 179 | end 180 | -------------------------------------------------------------------------------- /spec/jekyll-graph/feature_basic_default_sem_tree_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "spec_helper" 4 | 5 | RSpec.describe(Jekyll::Graph::Generator) do 6 | let(:config) do 7 | Jekyll.configuration( 8 | config_overrides.merge( 9 | "collections" => { "docs_tree" => { "output" => true } }, 10 | "permalink" => "pretty", 11 | "skip_config_files" => false, 12 | "source" => fixtures_dir, 13 | "destination" => site_dir, 14 | "url" => "garden.testsite.com", 15 | "testing" => true, 16 | # "baseurl" => "", 17 | "wikilinks" => { "enabled" => false }, 18 | ) 19 | ) 20 | end 21 | # set configs to only test the tree graph 22 | let(:config_overrides) { { 23 | # "namespaces" => { "exclude" => [ "docs_net_web" ] }, 24 | "graph" => { "net_web" => { "enabled" => false } } 25 | } } 26 | let(:site) { Jekyll::Site.new(config) } 27 | 28 | let(:doc_root) { find_by_title(site.collections["docs_tree"].docs, "Root") } 29 | let(:doc_second_lvl) { find_by_title(site.collections["docs_tree"].docs, "Root Second Level") } 30 | let(:doc_missing_lvl) { find_by_title(site.collections["docs_tree"].docs, "Missing Level") } 31 | 32 | let(:graph_data) { static_graph_file_content("tree") } 33 | let(:graph_generated_fpath) { find_generated_file("/assets/graph-tree.json") } 34 | let(:graph_root) { get_graph_root() } 35 | let(:graph_link) { get_graph_link_match_source("tree") } 36 | let(:graph_node) { get_graph_node("tree") } 37 | let(:missing_graph_node) { get_missing_graph_node() } 38 | 39 | # makes markdown tests work 40 | subject { described_class.new(site.config) } 41 | 42 | before(:each) do 43 | site.reset 44 | site.process 45 | end 46 | 47 | after(:each) do 48 | # cleanup _site/ dir 49 | FileUtils.rm_rf(Dir["#{site_dir()}"]) 50 | end 51 | 52 | context "GRAPH TYPE: TREE" do 53 | 54 | context "dependencies" do 55 | 56 | context "if 'tree' is enabled, but 'jekyll-semtree' not enabled (or installed)" do 57 | let(:config_overrides) { { "semtree" => { "enabled" => false } } } 58 | pending("todo: this is hard to test because i need to somehow mock the lack of plugin installation") 59 | 60 | # it "throw error if jekyll-semtree' 'tree' is missing" do 61 | # expect { Jekyll.logger.error }.to raise_error(ArgumentError) 62 | # end 63 | 64 | end 65 | 66 | end 67 | 68 | context "when doc for tree.path level exists" do 69 | 70 | it "generates graph data" do 71 | expect(graph_generated_fpath).to eq(File.join(site_dir, "/assets/graph-tree.json")) 72 | expect(graph_data.class).to be(Hash) 73 | end 74 | 75 | context "json node" do 76 | 77 | it "has format: { nodes: [ {id: '', url: '', label: ''}, ... ] }" do 78 | expect(graph_node.keys).to include("id") 79 | expect(graph_node.keys).to include("url") 80 | expect(graph_node.keys).to include("label") 81 | end 82 | 83 | it "'id's equal their url (since urls should be unique)" do 84 | expect(graph_root["id"]).to eq(graph_root["url"]) 85 | end 86 | 87 | it "'label's equal their doc title" do 88 | expect(graph_root["label"]).to eq(doc_root.data["title"]) 89 | end 90 | 91 | it "root 'namespace's equal their doc filename" do 92 | expect(graph_root["namespace"]).to eq(doc_root.basename_without_ext) 93 | end 94 | 95 | it "non-root 'namespace's equal their doc filename with the 'root.' prefix" do 96 | expect(graph_node["namespace"]).to eq("root." + doc_second_lvl.basename_without_ext) 97 | end 98 | 99 | it "'url's equal their doc urls" do 100 | expect(graph_root["url"]).to eq(doc_root.url) 101 | end 102 | 103 | it "'lineage' is an object with keys 'nodes' and 'links'" do 104 | expect(graph_root["lineage"]).to be_a(Object) 105 | expect(graph_root["lineage"].keys).to eq(["nodes", "links"]) 106 | end 107 | 108 | it "'lineage' 'node' is an array of 'id's" do 109 | expect(graph_root["lineage"]["nodes"]).to be_a(Array) 110 | expect(graph_root["lineage"]["nodes"][0]).to be_a(String) 111 | expect(graph_root["lineage"]["nodes"]).to eq([ 112 | "/one-page/", 113 | "/2020/12/08/one-post/", 114 | "root.blank", 115 | "/docs_tree/blank.missing-lvl/", 116 | "/docs_tree/second-level/", 117 | "/docs_tree/second-level.third-level/", 118 | "/docs_tree/root/" 119 | ]) 120 | end 121 | 122 | it "'lineage' 'link' is an array of objects with 'source' and 'target' keys which are node ids" do 123 | expect(graph_root["lineage"]["links"]).to be_a(Array) 124 | expect(graph_root["lineage"]["links"][0].keys).to eq(["source", "target"]) 125 | expect(graph_root["lineage"]["links"]).to eq([ 126 | {"source"=>"/docs_tree/root/", "target"=>"/one-page/"}, 127 | {"source"=>"/docs_tree/root/", "target"=>"/2020/12/08/one-post/"}, 128 | {"source"=>"/docs_tree/root/", "target"=>"root.blank"}, 129 | {"source"=>"root.blank", "target"=>"/docs_tree/blank.missing-lvl/"}, 130 | {"source"=>"/docs_tree/root/", "target"=>"/docs_tree/second-level/"}, 131 | {"source"=>"/docs_tree/second-level/", "target"=>"/docs_tree/second-level.third-level/"} 132 | ]) 133 | end 134 | 135 | end 136 | 137 | context "json link" do 138 | 139 | it "has format: { links: [ { source: '', target: '', label: ''}, ... ] }" do 140 | expect(graph_link.keys).to include("source") 141 | expect(graph_link.keys).to include("target") 142 | end 143 | 144 | it "'source' equals the parent id" do 145 | expect(graph_link["source"]).to eq(graph_root["id"]) 146 | expect(graph_root["id"]).to eq("/docs_tree/root/") 147 | end 148 | 149 | it "'target' equals the child id" do 150 | expect(graph_link["target"]).to eq(graph_node["id"]) 151 | expect(graph_node["id"]).to eq("/docs_tree/second-level/") 152 | end 153 | 154 | end 155 | 156 | end 157 | 158 | context "when doc for tree.path level does not exist" do 159 | 160 | it "generates graph data" do 161 | expect(graph_generated_fpath).to eq(File.join(site_dir, "/assets/graph-tree.json")) 162 | expect(graph_data.class).to be(Hash) 163 | end 164 | 165 | context "parent of missing node" do 166 | 167 | it "has namespace of missing level in its child metadata" do 168 | expect(doc_root["children"]).to include("root.blank") 169 | end 170 | 171 | end 172 | 173 | context "missing node" do 174 | 175 | it "has keys: [ 'id', 'label', 'namespace', and 'url' ]" do 176 | expect(missing_graph_node.keys).to include("id") 177 | expect(missing_graph_node.keys).to include("label") 178 | expect(missing_graph_node.keys).to include("namespace") 179 | expect(missing_graph_node.keys).to include("url") 180 | end 181 | 182 | it "'id's equals its namespace" do 183 | expect(missing_graph_node["id"]).to eq(missing_graph_node["namespace"]) 184 | end 185 | 186 | it "'label' equals the namespace of the missing level" do 187 | expect(missing_graph_node["label"]).to eq("blank") 188 | end 189 | 190 | it "'url' is an empty string" do 191 | expect(missing_graph_node["url"]).to eq("") 192 | end 193 | 194 | end 195 | 196 | end 197 | 198 | end 199 | 200 | end 201 | -------------------------------------------------------------------------------- /spec/jekyll-graph/feature_basic_default_web_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "spec_helper" 4 | 5 | RSpec.describe(Jekyll::Graph::Generator) do 6 | let(:config) do 7 | Jekyll.configuration( 8 | config_overrides.merge( 9 | "collections" => { "docs_web" => { "output" => true } }, 10 | "permalink" => "pretty", 11 | "skip_config_files" => false, 12 | "source" => fixtures_dir, 13 | "destination" => site_dir, 14 | "url" => "garden.testsite.com", 15 | "testing" => true, 16 | # "baseurl" => "", 17 | "namespaces" => { "enabled" => false }, 18 | ) 19 | ) 20 | end 21 | # set configs to only test the web graph 22 | let(:config_overrides) { { 23 | "wikilinks" => { "exclude" => [ "docs_tree" ] }, 24 | "graph" => { "tree" => { "enabled" => false } }, 25 | } } 26 | let(:site) { Jekyll::Site.new(config) } 27 | 28 | let(:untyped_link_doc) { find_by_title(site.collections["docs_web"].docs, "Untyped Link") } 29 | let(:blank_a) { find_by_title(site.collections["docs_web"].docs, "Base Case A") } 30 | let(:missing_doc) { find_by_title(site.collections["docs_web"].docs, "Untyped Link Missing Doc") } 31 | 32 | let(:graph_data) { static_graph_file_content("web") } 33 | let(:graph_generated_fpath) { find_generated_file("/assets/graph-web.json") } 34 | let(:graph_node) { get_graph_node("web") } 35 | let(:graph_link) { get_graph_link_match_source("web") } 36 | let(:missing_link_graph_node) { get_missing_link_graph_node() } 37 | let(:missing_target_graph_link) { get_missing_target_graph_link() } 38 | 39 | # makes markdown tests work 40 | subject { described_class.new(site.config) } 41 | 42 | before(:each) do 43 | site.reset 44 | site.process 45 | end 46 | 47 | after(:each) do 48 | # cleanup _site/ dir 49 | FileUtils.rm_rf(Dir["#{site_dir()}"]) 50 | end 51 | 52 | context "GRAPH TYPE: WEB" do 53 | 54 | context "dependencies" do 55 | 56 | context "require site object has 'link_index' attribute (because jekyll-wikilinks was not enabled/installed)" do 57 | let(:config_overrides) { { "wikilinks" => { "enabled" => false } } } 58 | pending("todo: this is hard to test because i need to somehow mock the lack of plugin installation") 59 | 60 | # it "throw error if jekyll-wikilinks' 'link_index' is missing" do 61 | # expect { Jekyll.logger.error }.to raise_error 62 | # end 63 | 64 | end 65 | 66 | end 67 | 68 | context "when target [[wikilink]] doc exists" do 69 | 70 | it "generates graph data" do 71 | expect(graph_generated_fpath).to eq(File.join(site_dir, "/assets/graph-web.json")) 72 | expect(graph_data.class).to be(Hash) 73 | end 74 | 75 | context "node" do 76 | 77 | it "keys include 'id' 'url' 'label'" do 78 | expect(graph_node.keys).to include("id") 79 | expect(graph_node.keys).to include("url") 80 | expect(graph_node.keys).to include("label") 81 | end 82 | 83 | it "'id' equals their url (since urls should be unique)" do 84 | expect(graph_node["id"]).to eq(graph_node["url"]) 85 | end 86 | 87 | it "'label' equals their doc title" do 88 | expect(graph_node["label"]).to eq(untyped_link_doc.data["title"]) 89 | end 90 | 91 | it "'url's equal their doc urls" do 92 | expect(graph_node["url"]).to eq(untyped_link_doc.url) 93 | end 94 | 95 | it "'neighbors' is an object with keys 'nodes' and 'links'" do 96 | expect(graph_node["neighbors"]).to be_a(Object) 97 | expect(graph_node["neighbors"].keys).to eq(["nodes", "links"]) 98 | end 99 | 100 | it "'neighbors' 'node' is an id" do 101 | expect(graph_node["neighbors"]["nodes"]).to be_a(Array) 102 | expect(graph_node["neighbors"]["nodes"]).to eq([ 103 | "/docs_web/blank.a/", 104 | ]) 105 | end 106 | 107 | it "'neighbors' 'link' is an object with 'source' and 'target', which are node ids" do 108 | expect(graph_node["neighbors"]["links"]).to be_a(Array) 109 | expect(graph_node["neighbors"]["links"]).to eq([ 110 | {"source"=>"/docs_web/link/", "target"=>"/docs_web/blank.a/"}, 111 | ]) 112 | end 113 | 114 | end 115 | 116 | context "link" do 117 | 118 | it "contains keys 'source' and 'target'" do 119 | expect(graph_link.keys).to eq(["source", "target"]) 120 | end 121 | 122 | it "'source' and 'target' attributes equal some nodes' id" do 123 | expect(graph_link["source"]).to eq(graph_node["id"]) 124 | expect(graph_link["target"]).to eq("/docs_web/blank.a/") 125 | end 126 | 127 | end 128 | 129 | end 130 | 131 | context "when target [[wikilink]] doc does not exist" do 132 | 133 | it "generates graph data" do 134 | expect(graph_generated_fpath).to eq(File.join(site_dir, "/assets/graph-web.json")) 135 | expect(graph_data.class).to be(Hash) 136 | end 137 | 138 | context "node" do 139 | 140 | it "keys include 'id', 'url', and 'label'" do 141 | expect(missing_link_graph_node.keys).to include("id") 142 | expect(missing_link_graph_node.keys).to include("url") 143 | expect(missing_link_graph_node.keys).to include("label") 144 | end 145 | 146 | it "'id's equal the original [[wikitext]]" do 147 | expect(missing_link_graph_node["id"]).to eq("missing.doc") 148 | end 149 | 150 | it "'label's equal the original [[wikitext]]" do 151 | expect(missing_link_graph_node["label"]).to eq("missing.doc") 152 | end 153 | 154 | it "'url's are empty strings" do 155 | expect(missing_link_graph_node["url"]).to eq("") 156 | end 157 | 158 | end 159 | 160 | context "link" do 161 | 162 | it "contains keys 'source' and 'target'" do 163 | expect(missing_target_graph_link.keys).to eq(["source", "target"]) 164 | end 165 | 166 | it "missing 'target' equals the [[wikitext]] in brackets." do 167 | expect(missing_target_graph_link["target"]).to eq("missing.doc") 168 | end 169 | 170 | end 171 | 172 | end 173 | 174 | end 175 | 176 | end 177 | -------------------------------------------------------------------------------- /spec/jekyll-graph/feature_config_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "spec_helper" 4 | 5 | RSpec.describe(Jekyll::Graph::Generator) do 6 | let(:config) do 7 | Jekyll.configuration( 8 | config_overrides.merge( 9 | "collections" => { 10 | "docs_net_web" => { "output" => true }, 11 | "docs_tree" => { "output" => true }, 12 | }, 13 | "permalink" => "pretty", 14 | "skip_config_files" => false, 15 | "source" => fixtures_dir, 16 | "destination" => site_dir, 17 | "url" => "garden.testsite.com", 18 | "testing" => true, 19 | # "baseurl" => "", 20 | ) 21 | ) 22 | end 23 | 24 | # let(:config_overrides) { { } } 25 | let(:site) { Jekyll::Site.new(config) } 26 | 27 | let(:net_web_graph_data) { static_graph_file_content("net-web") } 28 | let(:tree_web_graph_data) { static_graph_file_content("tree") } 29 | 30 | let(:block_link_doc) { find_by_title(site.collections["docs_net_web"].docs, "Block Single Link") } 31 | let(:untyped_link_doc) { find_by_title(site.collections["docs_net_web"].docs, "Untyped Link") } 32 | let(:blank_a) { find_by_title(site.collections["docs_net_web"].docs, "Base Case A") } 33 | 34 | # makes markdown tests work 35 | subject { described_class.new(site.config) } 36 | 37 | before(:each) do 38 | site.reset 39 | site.process 40 | end 41 | 42 | after(:each) do 43 | # cleanup _site/ dir 44 | FileUtils.rm_rf(Dir["#{site_dir()}"]) 45 | end 46 | 47 | context "CONFIG" do 48 | 49 | context "when disabled" do 50 | let(:config_overrides) { { "graph" => { "enabled" => false } } } 51 | 52 | it "does not generate graph data" do 53 | # net-web 54 | expect { File.read("#{site_dir("/assets/graph-net-web.json")}") }.to raise_error(Errno::ENOENT) 55 | expect { File.read("#{site_dir("/assets/graph-net-web.json")}") }.to raise_error(Errno::ENOENT) 56 | # tree 57 | expect { File.read("#{site_dir("/assets/graph-tree.json")}") }.to raise_error(Errno::ENOENT) 58 | expect { File.read("#{site_dir("/assets/graph-tree.json")}") }.to raise_error(Errno::ENOENT) 59 | end 60 | 61 | end 62 | 63 | context "when certain jekyll types are excluded" do 64 | let(:config_overrides) { { 65 | "graph" => { "exclude" => [ "pages", "posts" ] } 66 | } } 67 | 68 | it "does not generate graph data for those jekyll types" do 69 | # net-web 70 | expect(net_web_graph_data["nodes"].find { |n| n["title"] == "One Page" }).to eql(nil) 71 | expect(net_web_graph_data["nodes"].find { |n| n["title"] == "One Post" }).to eql(nil) 72 | expect(net_web_graph_data["links"].find { |n| n["source"] == "One Page" }).to eql(nil) 73 | expect(net_web_graph_data["links"].find { |n| n["source"] == "One Post" }).to eql(nil) 74 | # tree 75 | expect(tree_web_graph_data["nodes"].find { |n| n["title"] == "One Page" }).to eql(nil) 76 | expect(tree_web_graph_data["nodes"].find { |n| n["title"] == "One Post" }).to eql(nil) 77 | expect(tree_web_graph_data["links"].find { |n| n["source"] == "One Page" }).to eql(nil) 78 | expect(tree_web_graph_data["links"].find { |n| n["source"] == "One Post" }).to eql(nil) 79 | end 80 | 81 | end 82 | 83 | context "when assets location is set" do 84 | let(:config_overrides) { { 85 | "graph" => { 86 | "path" => { 87 | "assets" => "/custom_assets_path" 88 | } 89 | } 90 | } } 91 | 92 | it "writes graph file to custom location" do 93 | # net-web 94 | expect(file_generated?("/custom_assets_path/graph-net-web.json")).to eq(true) 95 | # tree 96 | expect(file_generated?("/custom_assets_path/graph-tree.json")).to eq(true) 97 | # scripts 98 | expect(file_generated?("/custom_assets_path/js/jekyll-graph.js")).to eq(true) 99 | end 100 | 101 | end 102 | 103 | context "when scripts location is set" do 104 | let(:config_overrides) { { 105 | "graph" => { 106 | "path" => { 107 | "scripts" => "/custom_scripts_path" 108 | } 109 | } 110 | } } 111 | 112 | it "writes graph file to custom location" do 113 | # net-web 114 | expect(file_generated?("/assets/graph-net-web.json")).to eq(true) 115 | # tree 116 | expect(file_generated?("/assets/graph-tree.json")).to eq(true) 117 | # scripts 118 | expect(file_generated?("/assets/custom_scripts_path/jekyll-graph.js")).to eq(true) 119 | end 120 | 121 | end 122 | 123 | context "NET-WEB 'exclude'" do 124 | 125 | context "when 'attrs' not included" do 126 | let(:config_overrides) { { 127 | "graph" => { 128 | "net_web" => { 129 | "exclude" => { 130 | "attrs" => false 131 | } 132 | } 133 | } 134 | } } 135 | 136 | it "does not include 'attributes'/'attributed' nodes/links" do 137 | expect(net_web_graph_data["links"].find { |l| l["source"] == "/docs_net_web/link.block/" && l["target"] == "/docs_net_web/blank.a/" }).to eq( 138 | "source" => "/docs_net_web/link.block/", 139 | "target" => "/docs_net_web/blank.a/", 140 | ) 141 | end 142 | 143 | end 144 | 145 | context "when 'links' not included" do 146 | let(:config_overrides) { { 147 | "graph" => { 148 | "net_web" => { 149 | "exclude" => { 150 | "links" => false 151 | } 152 | } 153 | } 154 | } } 155 | 156 | it "does not include 'forelink'/'backlink' nodes/links" do 157 | expect(net_web_graph_data["links"].find { |l| l["source"] == "/docs_net_web/link/" && l["target"] == "/docs_net_web/blank.a/" }).to eq( 158 | "source" => "/docs_net_web/link/", 159 | "target" => "/docs_net_web/blank.a/", 160 | ) 161 | end 162 | 163 | end 164 | 165 | end 166 | 167 | end 168 | 169 | end 170 | -------------------------------------------------------------------------------- /spec/jekyll-graph/version_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "spec_helper" 4 | 5 | RSpec.describe(Jekyll::Graph) do 6 | 7 | it "has a version number" do 8 | expect(Jekyll::Graph::VERSION).not_to be nil 9 | end 10 | 11 | end 12 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "jekyll-graph" 4 | require "jekyll-namespaces" 5 | require "jekyll-wikilinks" 6 | 7 | Jekyll.logger.log_level = :error 8 | 9 | RSpec.configure do |config| 10 | FIXTURES_DIR = File.expand_path("fixtures", __dir__) 11 | SITE_DIR = File.expand_path("_site", __dir__) 12 | 13 | def fixtures_dir(*files) 14 | File.join(FIXTURES_DIR, *files) 15 | end 16 | 17 | def site_dir(*files) 18 | File.join(SITE_DIR, *files) 19 | end 20 | 21 | # Enable flags like --only-failures and --next-failure 22 | config.example_status_persistence_file_path = ".rspec_status" 23 | 24 | # Disable RSpec exposing methods globally on `Module` and `main` 25 | config.disable_monkey_patching! 26 | 27 | config.expect_with :rspec do |c| 28 | c.syntax = :expect 29 | end 30 | 31 | # expected retrieval helpers 32 | 33 | def find_by_title(docs, title) 34 | docs.find { |d| d.data["title"] == title } 35 | end 36 | 37 | def find_generated_file(relative_path) 38 | site_dir(relative_path) 39 | end 40 | 41 | def file_generated?(relative_path) 42 | File.file?(site_dir(relative_path)) 43 | end 44 | 45 | def find_static_file(relative_path) 46 | site.static_files.find { |sf| sf.relative_path == relative_path } 47 | end 48 | 49 | ## graph retrieval helpers 50 | 51 | def static_graph_file_content(type) 52 | if type == "tree" 53 | graph_file = File.read(site_dir("/assets/graph-tree.json")) 54 | elsif type == "web" 55 | graph_file = File.read(site_dir("/assets/graph-web.json")) 56 | # deprecated: 'net_web' -> 'web' 57 | elsif type == "net-web" 58 | graph_file = File.read(site_dir("/assets/graph-net-web.json")) 59 | else 60 | Jekyll.logger.error("Invalid graph type #{type}") 61 | end 62 | JSON.parse(graph_file) 63 | end 64 | 65 | # TODO: write better graph data getters 66 | 67 | def get_graph_node(type) 68 | if type == "tree" 69 | graph_file = File.read(site_dir("/assets/graph-tree.json")) 70 | JSON.parse(graph_file)["nodes"].find { |n| n["namespace"] == "root.second-level" } 71 | elsif type == "web" 72 | graph_file = File.read(site_dir("/assets/graph-web.json")) 73 | JSON.parse(graph_file)["nodes"].find { |n| n["id"] == "/docs_web/link/" } 74 | # deprecated: 'net_web' -> 'web' 75 | elsif type == "net-web" 76 | graph_file = File.read(site_dir("/assets/graph-net-web.json")) 77 | JSON.parse(graph_file)["nodes"].find { |n| n["id"] == "/docs_net_web/link/" } 78 | else 79 | Jekyll.logger.error("Invalid graph type #{type}") 80 | end 81 | end 82 | 83 | def get_graph_link_match_source(type) 84 | if type == "tree" 85 | graph_file = File.read(site_dir("/assets/graph-tree.json")) 86 | all_links = JSON.parse(graph_file)["links"] 87 | target_link = all_links.find_all { |l| l["source"] == "/docs_tree/root/" && l["target"] == "/docs_tree/second-level/" } # link "Root" -> "Second Level" 88 | if target_link.size > 1 89 | raise "Expected only one link with 'source' as \"Base Case A\" note to exist." 90 | else 91 | return target_link[0] 92 | end 93 | elsif type == "web" 94 | graph_file = File.read(site_dir("/assets/graph-web.json")) 95 | all_links = JSON.parse(graph_file)["links"] 96 | target_link = all_links.find_all { |l| l["source"] == "/docs_web/link/" && l["target"] == "/docs_web/blank.a/" } # link "Untyped Link" -> "Blank A" 97 | if target_link.size > 1 98 | raise "Expected only one link with 'source' as \"Base Case A\" note to exist." 99 | else 100 | return target_link[0] 101 | end 102 | # deprecated: 'net_web' -> 'web' 103 | elsif type == "net-web" 104 | graph_file = File.read(site_dir("/assets/graph-net-web.json")) 105 | all_links = JSON.parse(graph_file)["links"] 106 | target_link = all_links.find_all { |l| l["source"] == "/docs_net_web/link/" && l["target"] == "/docs_net_web/blank.a/" } # link "Untyped Link" -> "Blank A" 107 | if target_link.size > 1 108 | raise "Expected only one link with 'source' as \"Base Case A\" note to exist." 109 | else 110 | return target_link[0] 111 | end 112 | else 113 | Jekyll.logger.error("Invalid graph type #{type}") 114 | end 115 | end 116 | 117 | # net-web / web 118 | 119 | def get_missing_link_graph_node(legacy = false) 120 | if legacy 121 | graph_file = File.read(site_dir("/assets/graph-net-web.json")) 122 | else 123 | graph_file = File.read(site_dir("/assets/graph-web.json")) 124 | end 125 | JSON.parse(graph_file)["nodes"].find { |n| n["id"] == "missing.doc" } # "Missing Doc" 126 | end 127 | 128 | def get_missing_target_graph_link(legacy = false) 129 | if legacy 130 | graph_file = File.read(site_dir("/assets/graph-net-web.json")) 131 | all_links = JSON.parse(graph_file)["links"] 132 | target_link = all_links.find_all { |l| l["source"] == "/docs_net_web/link.missing-doc/" } # "Missing Doc" link as source 133 | else 134 | graph_file = File.read(site_dir("/assets/graph-web.json")) 135 | all_links = JSON.parse(graph_file)["links"] 136 | target_link = all_links.find_all { |l| l["source"] == "/docs_web/link.missing-doc/" } # "Missing Doc" link as source 137 | end 138 | if target_link.size > 1 139 | raise "Expected only one link with 'source' as \"Missing Doc\" note to exist." 140 | else 141 | return target_link[0] 142 | end 143 | end 144 | 145 | # tree 146 | 147 | def get_graph_root() 148 | graph_file = File.read(site_dir("/assets/graph-tree.json")) 149 | JSON.parse(graph_file)["nodes"].find { |n| n["namespace"] == "root" } # "Root Level" 150 | end 151 | 152 | def get_missing_graph_node() 153 | graph_file = File.read(site_dir("/assets/graph-tree.json")) 154 | JSON.parse(graph_file)["nodes"].find { |n| n["namespace"] == "root.blank" } # "Blank" 155 | end 156 | 157 | 158 | # comments from: https://github.com/jekyll/jekyll-mentions/blob/master/spec/spec_helper.rb 159 | 160 | # rspec-mocks config goes here. You can use an alternate test double 161 | # library (such as bogus or mocha) by changing the `mock_with` option here. 162 | config.mock_with :rspec do |mocks| 163 | # Prevents you from mocking or stubbing a method that does not exist on 164 | # a real object. This is generally recommended, and will default to 165 | # `true` in RSpec 4. 166 | mocks.verify_partial_doubles = true 167 | end 168 | 169 | # comments from: https://github.com/jekyll/jekyll-mentions/blob/master/spec/spec_helper.rb 170 | 171 | # These two settings work together to allow you to limit a spec run 172 | # to individual examples or groups you care about by tagging them with 173 | # `:focus` metadata. When nothing is tagged with `:focus`, all examples 174 | # get run. 175 | config.filter_run :focus 176 | config.run_all_when_everything_filtered = true 177 | 178 | # Limits the available syntax to the non-monkey patched syntax that is recommended. 179 | # For more details, see: 180 | # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax 181 | # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ 182 | # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching 183 | config.disable_monkey_patching! 184 | 185 | # Run specs in random order to surface order dependencies. If you find an 186 | # order dependency and want to debug it, you can fix the order by providing 187 | # the seed, which is printed after each run. 188 | # --seed 1234 189 | config.order = :random 190 | 191 | # Seed global randomization in this process using the `--seed` CLI option. 192 | # Setting this allows you to use `--seed` to deterministically reproduce 193 | # test failures related to randomization by passing the same `--seed` value 194 | # as the one that triggered the failure. 195 | Kernel.srand config.seed 196 | end 197 | --------------------------------------------------------------------------------