forked from fediversity/fediversity
		
	implement navigation
This commit is contained in:
		
							parent
							
								
									3a36a6cf29
								
							
						
					
					
						commit
						ad8b758cee
					
				
					 5 changed files with 93 additions and 4 deletions
				
			
		
							
								
								
									
										21
									
								
								website/content/navigation.nix
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								website/content/navigation.nix
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,21 @@
 | 
			
		|||
{ config, ... }:
 | 
			
		||||
let
 | 
			
		||||
  inherit (config) pages;
 | 
			
		||||
in
 | 
			
		||||
{
 | 
			
		||||
  menus.main = {
 | 
			
		||||
    label = "Main";
 | 
			
		||||
    items = [
 | 
			
		||||
      {
 | 
			
		||||
        menu.label = "Consortium";
 | 
			
		||||
        menu.items = map (page: { inherit page; }) (with pages; [ nlnet oid tweag nordunet ]);
 | 
			
		||||
      }
 | 
			
		||||
      {
 | 
			
		||||
        page = pages.fediversity;
 | 
			
		||||
      }
 | 
			
		||||
      {
 | 
			
		||||
        page = pages.grants;
 | 
			
		||||
      }
 | 
			
		||||
    ];
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -37,7 +37,10 @@ in
 | 
			
		|||
            <meta name="description" content="${page.description}" />
 | 
			
		||||
            <link rel="canonical" href="${page.outPath}" />
 | 
			
		||||
          '';
 | 
			
		||||
          body = builtins.readFile (commonmark page.name page.body);
 | 
			
		||||
          body = ''
 | 
			
		||||
            ${templates.nav { menu = { menu = config.menus.main; }; }}
 | 
			
		||||
            ${builtins.readFile (commonmark page.name page.body)}
 | 
			
		||||
          '';
 | 
			
		||||
        });
 | 
			
		||||
      });
 | 
			
		||||
      article = lib.mkDefault (config: page: {
 | 
			
		||||
| 
						 | 
				
			
			@ -48,7 +51,10 @@ in
 | 
			
		|||
            <meta name="description" content="${page.description}" />
 | 
			
		||||
            <meta name="author" content="${with lib; if isList page.author then join ", " page.author else page.author}" />
 | 
			
		||||
          '';
 | 
			
		||||
          body = builtins.readFile (commonmark page.name page.body);
 | 
			
		||||
          body = ''
 | 
			
		||||
            ${templates.nav { menu = { menu = config.menus.main; }; }}
 | 
			
		||||
            ${builtins.readFile (commonmark page.name page.body)}
 | 
			
		||||
          '';
 | 
			
		||||
        });
 | 
			
		||||
      });
 | 
			
		||||
    };
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
{ lib }:
 | 
			
		||||
{
 | 
			
		||||
rec {
 | 
			
		||||
  html = { head, body }: ''
 | 
			
		||||
    <!DOCTYPE html>
 | 
			
		||||
    <html>
 | 
			
		||||
| 
						 | 
				
			
			@ -14,4 +14,24 @@
 | 
			
		|||
      <body>
 | 
			
		||||
    </html>
 | 
			
		||||
  '';
 | 
			
		||||
  nav = { menu }:
 | 
			
		||||
    let
 | 
			
		||||
      render-item = item:
 | 
			
		||||
        if item ? menu then
 | 
			
		||||
          ''
 | 
			
		||||
            <li>${item.menu.label}
 | 
			
		||||
            ${lib.indent "  " (nav { menu = item; })}
 | 
			
		||||
          ''
 | 
			
		||||
        else
 | 
			
		||||
          if item ? page then ''<li><a href="${item.page}">${item.page.title}</a></li>''
 | 
			
		||||
          else ''<li><a href="${item.link.url}">${item.link.label}</a></li>''
 | 
			
		||||
      ;
 | 
			
		||||
    in
 | 
			
		||||
    ''
 | 
			
		||||
      <nav>
 | 
			
		||||
        <ul>
 | 
			
		||||
        ${with lib; indent "    " (join "\n" (map render-item menu.menu.items))}
 | 
			
		||||
        </ul>
 | 
			
		||||
      </nav>
 | 
			
		||||
    '';
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,7 +17,7 @@ in
 | 
			
		|||
    page = { name, config, ... }: {
 | 
			
		||||
      options = {
 | 
			
		||||
        name = mkOption {
 | 
			
		||||
          description = "Symbolic name for the page, used as a human-readable identifier";
 | 
			
		||||
          description = "Symbolic name, used as a human-readable identifier";
 | 
			
		||||
          type = types.str;
 | 
			
		||||
          default = name;
 | 
			
		||||
        };
 | 
			
		||||
| 
						 | 
				
			
			@ -93,5 +93,41 @@ in
 | 
			
		|||
      config.outPath = "${collectionName}/${lib.head config.locations}";
 | 
			
		||||
      config.template = cfg.templates.article;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    named-link = { ... }: {
 | 
			
		||||
      options = {
 | 
			
		||||
        label = mkOption {
 | 
			
		||||
          description = "Link label";
 | 
			
		||||
          type = types.str;
 | 
			
		||||
        };
 | 
			
		||||
        url = mkOption {
 | 
			
		||||
          description = "Link URL";
 | 
			
		||||
          type = types.str;
 | 
			
		||||
        };
 | 
			
		||||
      };
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    navigation = { name, ... }: {
 | 
			
		||||
      options = {
 | 
			
		||||
        name = mkOption {
 | 
			
		||||
          description = "Symbolic name, used as a human-readable identifier";
 | 
			
		||||
          type = types.str;
 | 
			
		||||
          default = name;
 | 
			
		||||
        };
 | 
			
		||||
        label = mkOption {
 | 
			
		||||
          description = "Menu label";
 | 
			
		||||
          type = types.str;
 | 
			
		||||
          default = name;
 | 
			
		||||
        };
 | 
			
		||||
        items = mkOption {
 | 
			
		||||
          description = "List of menu items";
 | 
			
		||||
          type = with types; listOf (attrTag {
 | 
			
		||||
            menu = mkOption { type = submodule cfg.content-types.navigation; };
 | 
			
		||||
            page = mkOption { type = submodule cfg.content-types.page; };
 | 
			
		||||
            link = mkOption { type = submodule cfg.content-types.named-link; };
 | 
			
		||||
          });
 | 
			
		||||
        };
 | 
			
		||||
      };
 | 
			
		||||
    };
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -54,4 +54,10 @@ in
 | 
			
		|||
      }));
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
  options.menus = mkOption {
 | 
			
		||||
    description = ''
 | 
			
		||||
      Collection navigation menus
 | 
			
		||||
    '';
 | 
			
		||||
    type = with types; attrsOf (submodule config.content-types.navigation);
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue