Commits

Shlomi Fish committed f18614c

Generating an ID key to the JSON in NavMenu.

TODO : implement support for it in the client-side JS code.

  • Participants
  • Parent commits 95a6fae

Comments (0)

Files changed (3)

 
 generate_nav_data_as_json: $(NAV_DATA_AS_JSON)
 
-$(NAV_DATA_AS_JSON): $(NAV_DATA_DEP) $(NAV_DATA_AS_JSON_BIN)
+$(NAV_DATA_AS_JSON): $(NAV_DATA_DEP) $(NAV_DATA_AS_JSON_BIN) lib/Shlomif/Homepage/NavData/JSON.pm
 	./$(NAV_DATA_AS_JSON_BIN) -o $@
 
 generate_nav_data_as_json:

lib/Shlomif/Homepage/NavData/JSON.pm

 use MyNavData;
 
 use JSON qw(encode_json);
+use YAML::Syck ();
 
 sub output_fully_expanded_as_json
 {
         },
     );
 
-    my $filter_out_seperators;
+    my $id_persistence_filename =
+        File::Spec->catfile(
+            File::Spec->curdir(),
+            'lib', 'Shlomif', 'Homepage', 'NavData',
+            'JSON_Data_Persistence.yml',
+        );
 
-    $filter_out_seperators = sub {
+    my ($id_persistence) = YAML::Syck::LoadFile($id_persistence_filename);
+
+    $id_persistence ||= {
+        id_persistence => { next_id => 1, paths_ids => { }, },
+    };
+
+    my $ptr = $id_persistence->{id_persistence};
+
+    my $get_id_from_cache = sub
+    {
+        my $url = shift;
+        if (! exists($ptr->{paths_ids}->{$url}))
+        {
+            $ptr->{paths_ids}->{$url} = ($ptr->{next_id}++);
+        }
+        return $ptr->{paths_ids}->{$url};
+    };
+
+    my $process_sub_tree;
+
+    $process_sub_tree = sub
+    {
         my ($sub_tree) = @_;
 
         my @keys = (grep { $_ ne 'subs' } keys %{$sub_tree});
 
         my $has_subs = exists($sub_tree->{subs});
 
-        return {
+        return
+        {
+            (exists($sub_tree->{url})
+                ? (id => $get_id_from_cache->($sub_tree->{url}))
+                : ()
+            ),
             (map { $_ => $sub_tree->{$_} } @keys),
             $has_subs
-            ?  (subs => [ map { $filter_out_seperators->($_) }
+            ?  (subs => [ map { $process_sub_tree->($_) }
                     grep { ! exists($_->{separator}) }
                     @{$sub_tree->{subs}}
                 ])
             : (),
-        },
+        };
     };
 
-    return encode_json($filter_out_seperators->($params{tree_contents})->{'subs'});
+    my $ret = encode_json(
+        $process_sub_tree->($params{tree_contents})->{'subs'}
+    );
+
+    YAML::Syck::DumpFile(
+        $id_persistence_filename, $id_persistence,
+    );
+
+    return $ret;
 }
 
 1;

lib/Shlomif/Homepage/NavData/JSON_Data_Persistence.yml

+--- 
+id_persistence: 
+  next_id: 321
+  paths_ids: 
+    "": 1
+    DeCSS/: 288
+    MathVentures/: 99
+    MathVentures/3d-outof-4d-mathml.xhtml: 100
+    MathVentures/bugs-in-square-mathml.xhtml: 107
+    MathVentures/disco_circle.html: 103
+    MathVentures/dodeca.html: 102
+    MathVentures/repeating_code.html: 101
+    MathVentures/sequence-4-8-7-5.html: 108
+    MathVentures/toggle-squares/: 105
+    MathVentures/toggle_squares.html: 104
+    MathVentures/two-angels-and-two-gates.html: 109
+    SFresume.html: 8
+    SFresume_detailed.html: 9
+    art/: 120
+    art/better-scm/: 125
+    art/bk2hp/: 121
+    art/hhfg-background/: 124
+    art/linux_banner/: 122
+    art/made-with-latemp/: 123
+    art/slogans/: 126
+    grad-fu/: 134
+    humour-heb.html: 42
+    humour.html: 41
+    humour/: 13
+    humour/Blue-Rabbit-Log/: 35
+    humour/Blue-Rabbit-Log/ideas.xhtml: 37
+    humour/Blue-Rabbit-Log/part-1.html: 36
+    humour/GNU-Visual-Basic/GNU-Visual-Basic.html: 83
+    humour/Pope/: 21
+    humour/Pope/The-Pope-Died-on-Sunday--Hebrew-Text.html: 22
+    humour/RoadToHeaven/: 38
+    humour/RoadToHeaven/abstract.xhtml: 39
+    humour/Selena-Mandrake/: 33
+    humour/Selena-Mandrake/ongoing-text.html: 34
+    humour/Star-Trek/We-the-Living-Dead/: 31
+    humour/Star-Trek/We-the-Living-Dead/ongoing-text.html: 32
+    humour/TOWTF/: 18
+    humour/TOWTF/TOW_Fountainhead_1.html: 19
+    humour/TOWTF/TOW_Fountainhead_2.html: 20
+    humour/TheEnemy/: 15
+    humour/TheEnemy/The-Enemy-English-v7.html: 17
+    humour/TheEnemy/The-Enemy-Hebrew-v7.html: 16
+    humour/aphorisms/: 40
+    humour/bits/: 56
+    humour/bits/COBOL-the-New-Age-Programming-Language/: 70
+    humour/bits/Can-I-SCO-Now/: 74
+    humour/bits/Copying-Ubuntu-Bug-No-1/: 71
+    humour/bits/Crackas-Paradise/: 65
+    humour/bits/Freecell-Solver-Enterprise-Edition/: 69
+    humour/bits/GPL-is-not-Compatible-with-Itself/: 63
+    humour/bits/How-many-Wikipedia-Editors/: 68
+    humour/bits/I-Like-Job-Control/: 62
+    humour/bits/Im-The-Real-Tim-Toady/: 73
+    humour/bits/It-s-not-a-Fooware-It-s-an-Operating-System/: 72
+    humour/bits/Mastering-Cat/: 66
+    humour/bits/Programs-Every-Programmer-has-Written/: 67
+    humour/bits/RMS-Lint/: 64
+    humour/bits/Spam-for-Everyone/: 61
+    humour/bits/facts/: 75
+    humour/bits/facts/Chuck-Norris/: 76
+    humour/bits/facts/Knuth/: 77
+    humour/bits/facts/Larry-Wall/: 78
+    humour/bits/facts/XSLT/: 80
+    humour/bits/facts/Xena/: 79
+    humour/by-others/: 81
+    humour/by-others/English-is-a-Crazy-Language.html: 82
+    humour/by-others/darien--everybody-is-free.html: 84
+    humour/by-others/division-two/: 94
+    humour/by-others/grad-student-jokes-from-jnoakes/: 92
+    humour/by-others/hitchhiker-guide-to-star-trek-tng-htmlised.html: 87
+    humour/by-others/hitchhiker-guide-to-star-trek-tng.html: 86
+    humour/by-others/how-many-newsgroup-readers-does-it-take-to-change-a-lightbulb.html: 88
+    humour/by-others/oded-c/: 95
+    humour/by-others/s-stands-for-simple/: 90
+    humour/by-others/technion-bit-1.html: 85
+    humour/by-others/the-fountainhead-starring-skull-force/: 93
+    humour/by-others/top-12-things-likely-to-be-overheard-if-you-had-a-klingon-programmer.html: 89
+    humour/by-others/was-the-death-star-attack-an-inside-job/: 91
+    humour/fortunes/: 43
+    humour/fortunes/friends.html: 44
+    humour/fortunes/joel-on-software.html: 45
+    humour/fortunes/nyh-sigs.html: 46
+    humour/fortunes/osp_rules.html: 47
+    humour/fortunes/paul-graham.html: 48
+    humour/fortunes/sharp-perl.html: 49
+    humour/fortunes/sharp-programming.html: 50
+    humour/fortunes/shlomif-factoids.html: 52
+    humour/fortunes/shlomif-fav.html: 53
+    humour/fortunes/shlomif.html: 51
+    humour/fortunes/subversion.html: 54
+    humour/fortunes/tinic.html: 55
+    humour/human-hacking/: 27
+    humour/human-hacking/arabic-v2.html: 29
+    humour/human-hacking/conclusions/: 28
+    humour/human-hacking/hebrew-v2.html: 30
+    humour/humanity/: 23
+    humour/humanity/buy-the-fish-in-hebrew.html: 26
+    humour/humanity/ongoing-text-hebrew.html: 25
+    humour/humanity/ongoing-text.html: 24
+    humour/recommendations/: 96
+    humour/recommendations/films/: 97
+    humour/stories/: 14
+    humour/ways_to_do_it-heb.html: 58
+    humour/ways_to_do_it.html: 57
+    jmikmod/: 132
+    lecture/: 193
+    lecture/Autotools/: 207
+    lecture/CatB/: 198
+    lecture/Command-Line/: 221
+    lecture/Freecell-Solver/: 223
+    lecture/Freecell-Solver/The-Next-Pres/: 224
+    lecture/Freecell-Solver/project-intro/: 225
+    lecture/Gimp/: 204
+    lecture/HTML-Tutorial/: 195
+    lecture/LAMP/: 196
+    lecture/LM-Solve/: 226
+    lecture/Lambda-Calculus/: 201
+    lecture/Perl/Graham-Function/: 229
+    lecture/Perl/Haskell/: 202
+    lecture/Perl/Lightning/Mojolicious/: 234
+    lecture/Perl/Lightning/Opt-Multi-Task-in-PDL/: 231
+    lecture/Perl/Lightning/Test-Run/: 232
+    lecture/Perl/Lightning/Too-Many-Ways/: 233
+    lecture/Perl/Newbies/: 194
+    lecture/Perl/Template-Toolkit/: 230
+    lecture/PostgreSQL/: 205
+    lecture/Pres-Tools/Perl-Point/: 213
+    lecture/Quad-Pres/: 212
+    lecture/Sys-Call-Track/Lex-Yacc/: 206
+    lecture/Vim/beginners/: 209
+    lecture/Vim/telux-tips-and-tricks/: 210
+    lecture/W2L/: 214
+    lecture/W2L/Basic_Use/: 215
+    lecture/W2L/Blitz/: 218
+    lecture/W2L/Development/: 216
+    lecture/W2L/Mini-Intro/: 219
+    lecture/W2L/Network/: 217
+    lecture/W2L/Why_Linux/: 220
+    lecture/WebMetaLecture/: 208
+    lecture/cat/lightning-talks/: 227
+    lecture/cat/pres-tools/: 211
+    lecture/cat/programming-languages/: 200
+    lecture/cat/projects/: 222
+    lecture/cat/software-management/: 197
+    lecture/cat/various-tools/: 203
+    lecture/joel-test/: 199
+    lecture/mini/mdda/: 228
+    links.html: 308
+    me/: 2
+    me/blogs/: 11
+    me/contact-me/: 6
+    me/interviews/: 12
+    me/intros/: 4
+    me/intros/writers/: 5
+    me/personal-ad.html: 10
+    me/resumes/: 7
+    meta/: 311
+    meta/FAQ/: 312
+    meta/anti-spam-policy/: 319
+    meta/copyrights/: 316
+    meta/donate/: 314
+    meta/hosting/: 320
+    meta/how-to-help/: 313
+    meta/linking-policy/: 318
+    meta/privacy-policy/: 317
+    meta/site-source/: 315
+    no-ie/: 181
+    open-source/: 127
+    open-source/anti/: 180
+    open-source/anti/SOAP/: 191
+    open-source/anti/apple/: 184
+    open-source/anti/autohell/: 188
+    open-source/anti/csh/: 183
+    open-source/anti/java/: 190
+    open-source/anti/javascript/: 189
+    open-source/anti/mysql/: 186
+    open-source/anti/php/: 187
+    open-source/anti/qmail/: 182
+    open-source/anti/windows-vista/: 185
+    open-source/bits-and-bobs/greasemonkey/grease.html: 158
+    open-source/bits.html: 157
+    open-source/contributions/: 161
+    open-source/favourite/: 164
+    open-source/interviews/: 165
+    open-source/interviews/adrian-ettlinger.html: 166
+    open-source/interviews/sussman.html: 167
+    open-source/mentoring/: 162
+    open-source/nostalgia/: 192
+    open-source/portability-libs/: 168
+    open-source/projects/: 128
+    open-source/projects/File-Dir-Dumper/: 137
+    open-source/projects/File-Find-Object/: 143
+    open-source/projects/Module-Format/: 144
+    open-source/projects/Park-Lisp/: 155
+    open-source/projects/Spark/: 153
+    open-source/projects/Spark/mission/: 154
+    open-source/projects/Test.pm-Converter/: 145
+    open-source/projects/XML-Grammar/: 146
+    open-source/projects/XML-Grammar/Fiction/: 147
+    open-source/projects/black-hole-solitaire-solver/: 138
+    open-source/projects/conf/: 159
+    open-source/projects/conf/vim/: 160
+    open-source/projects/countdown/: 152
+    open-source/projects/docmake/: 148
+    open-source/projects/freecell-solver/: 129
+    open-source/projects/japanese-puzzle-games/: 139
+    open-source/projects/japanese-puzzle-games/abc-path/: 140
+    open-source/projects/japanese-puzzle-games/binary-puzzle/: 141
+    open-source/projects/japanese-puzzle-games/kakurasu/: 142
+    open-source/projects/latemp/: 130
+    open-source/projects/libtap/: 151
+    open-source/projects/linux-kernel/xconfig-search/: 156
+    open-source/projects/mikmod/: 131
+    open-source/projects/quad-pres/: 149
+    open-source/projects/website-meta-language/: 133
+    open-source/projects/yjobs-on-mozilla/: 150
+    open-source/resources/: 163
+    open-source/resources/editors-and-IDEs/: 170
+    open-source/resources/how-to-contribute-to-my-projects/: 175
+    open-source/resources/israel/: 177
+    open-source/resources/israel/guide-to-israeli-foss-resources/: 178
+    open-source/resources/israel/list-of-projects/: 179
+    open-source/resources/multimedia-programs/: 174
+    open-source/resources/networking-clients/: 173
+    open-source/resources/numerical-software/: 171
+    open-source/resources/software-tools/: 169
+    open-source/resources/text-processing-tools/: 172
+    personal.html: 3
+    philosophy/: 235
+    philosophy/Index/: 236
+    philosophy/books-recommends/: 237
+    philosophy/by-others/: 301
+    philosophy/by-others/james-carr--completely-overrated.html: 302
+    philosophy/by-others/mashhoor--10-reasons--hebrew.html: 303
+    philosophy/by-others/perlcast-transcript--tom-limoncelli-interview/: 304
+    philosophy/case-for-file-swapping/: 280
+    philosophy/case-for-file-swapping/revision-3/: 281
+    philosophy/computers/: 238
+    philosophy/computers/education/: 270
+    philosophy/computers/education/introductory-language/: 272
+    philosophy/computers/education/opinion-on-the-technion/: 271
+    philosophy/computers/high-quality-software/: 252
+    philosophy/computers/high-quality-software/rev2/: 253
+    philosophy/computers/open-source/: 241
+    philosophy/computers/open-source/foss-licences-wars/: 247
+    philosophy/computers/open-source/gpl-bsd-and-suckerism/: 245
+    philosophy/computers/open-source/how-to-start-contributing/: 243
+    philosophy/computers/open-source/how-to-start-contributing/tos-document.html: 244
+    philosophy/computers/open-source/linus-torvalds-bus-factor/: 246
+    philosophy/computers/optimizing-code-for-speed/: 254
+    philosophy/computers/perl/: 255
+    philosophy/computers/perl/joy-of-perl/: 258
+    philosophy/computers/perl/joy-of-perl/joy-of-perl.html: 259
+    philosophy/computers/perl/perl6-critique/: 260
+    philosophy/computers/software-management/: 248
+    philosophy/computers/software-management/end-of-it-slavery/: 249
+    philosophy/computers/software-management/perfect-workplace/: 250
+    philosophy/computers/software-management/perfect-workplace/perfect-it-workplace.xhtml: 251
+    philosophy/computers/web/: 261
+    philosophy/computers/web/choice-of-docs-formats/: 266
+    philosophy/computers/web/create-a-great-personal-homesite/: 262
+    philosophy/computers/web/create-a-great-personal-homesite/rev2.html: 263
+    philosophy/computers/web/homepage-vs-blog/: 268
+    philosophy/computers/web/online-communities/: 269
+    philosophy/computers/web/use-qmail-instead/: 267
+    philosophy/computers/web/which-wiki/: 264
+    philosophy/computers/web/which-wiki/update-2006-07/: 265
+    philosophy/computers/when-c-is-best/: 239
+    philosophy/computers/when-c-is-best/when-c-is-the-best.html: 240
+    philosophy/foss-other-beasts/: 242
+    philosophy/ideas/: 298
+    philosophy/ideas/fortunes-mania/: 299
+    philosophy/ideas/unixdoc/: 300
+    philosophy/israel-pales/: 279
+    philosophy/obj-oss/: 277
+    philosophy/obj-oss/rev2/: 278
+    philosophy/perl-newcomers/: 256
+    philosophy/perl-newcomers/v1/: 257
+    philosophy/philosophy/: 289
+    philosophy/philosophy/advice-for-the-young/: 292
+    philosophy/philosophy/closed-books-are-so-19th-century/: 293
+    philosophy/philosophy/guide-to-neo-tech/: 291
+    philosophy/politics/: 276
+    philosophy/politics/define-zionism/: 285
+    philosophy/politics/define-zionism/heb/: 286
+    philosophy/politics/dispelling-myths-about-israel/: 287
+    philosophy/politics/drug-legalisation/: 283
+    philosophy/politics/drug-legalisation/hebrew.html: 284
+    philosophy/politics/why-scientology-is-bad/: 282
+    philosophy/psychology/: 294
+    philosophy/psychology/elephant-in-the-circus/: 296
+    philosophy/psychology/elephant-in-the-circus/hebrew.html: 297
+    philosophy/psychology/hypomanias/: 295
+    philosophy/the-eternal-jew/: 290
+    prog-evolution/: 273
+    prog-evolution/pre-elpas.html: 274
+    prog-evolution/shlomif-at-elpas.html: 275
+    puzzles/: 98
+    puzzles/cs/: 118
+    puzzles/cs/lotg/: 119
+    puzzles/logic/: 110
+    puzzles/logic/between-the-screws/: 111
+    puzzles/logic/ravensborgs-guild/: 112
+    puzzles/logic/tip-of-the-sword/: 113
+    puzzles/maths/: 116
+    puzzles/maths/n5-riddle/: 117
+    puzzles/situation/: 114
+    puzzles/situation/book-under-rock.html: 115
+    recommendations/: 309
+    rindolf/: 176
+    rwlock/: 135
+    rwlock/linux-kernel/: 136
+    site-map/: 310
+    toggle.html: 106
+    wonderous.html: 60
+    work/: 305
+    work/hire-me/: 306
+    work/private-lessons/: 307
+    wysiwyt.html: 59