]> https://gitweb.dealii.org/ - dealii.git/commitdiff
doxygen: rewrite set_canonical_doxygen.py in Perl
authorFerdinand Vanmaele <Vanmaele@stud.uni-heidelberg.de>
Wed, 11 Sep 2019 12:46:28 +0000 (14:46 +0200)
committerFerdinand Vanmaele <Vanmaele@stud.uni-heidelberg.de>
Wed, 11 Sep 2019 12:46:28 +0000 (14:46 +0200)
Fixes issue #8735

doc/doxygen/CMakeLists.txt
doc/doxygen/scripts/set_canonical_doxygen.pl [new file with mode: 0644]
doc/doxygen/scripts/set_canonical_doxygen.py [deleted file]

index e611b3f705c8ac24f44f9e59b7e16873e96cb719..d47b0bab85d0b3976865604af4aa31c38f62ed5f 100644 (file)
@@ -284,8 +284,9 @@ ADD_CUSTOM_COMMAND(
     ${CMAKE_CURRENT_BINARY_DIR}/options.dox
     > ${CMAKE_BINARY_DIR}/doxygen.log 2>&1 # *pssst*
     || ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/doxygen.log ${CMAKE_BINARY_DIR}/doxygen.err
-  COMMAND
-    ${CMAKE_CURRENT_SOURCE_DIR}/scripts/set_canonical_doxygen.py
+  COMMAND ${PERL_EXECUTABLE}
+  ARGS
+    ${CMAKE_CURRENT_SOURCE_DIR}/scripts/set_canonical_doxygen.pl
   WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
   DEPENDS
     tutorial
diff --git a/doc/doxygen/scripts/set_canonical_doxygen.pl b/doc/doxygen/scripts/set_canonical_doxygen.pl
new file mode 100644 (file)
index 0000000..51af255
--- /dev/null
@@ -0,0 +1,93 @@
+## ---------------------------------------------------------------------
+##
+## Copyright (C) 2019 by the deal.II authors
+##
+## This file is part of the deal.II library.
+##
+## The deal.II library is free software; you can use it, redistribute
+## it, and/or modify it under the terms of the GNU Lesser General
+## Public License as published by the Free Software Foundation; either
+## version 2.1 of the License, or (at your option) any later version.
+## The full text of the license can be found in the file LICENSE at
+## the top level of the deal.II distribution.
+##
+## ---------------------------------------------------------------------
+
+# This script sets the canonical webpage for all the webpages of the
+# doxygen documentation. For more information see
+# https://en.wikipedia.org/wiki/Canonical_link_element
+#
+# This script is invoked by CMake. To add the canonical link to the webpages of
+# the deal.ii repository you can use the script
+# contrib/utilities/set_canonical_webpages.py
+
+use strict;
+use warnings;
+
+use File::Find qw(find);
+
+my @html;
+my $link_start = '<link rel="canonical" href="https://www.dealii.org/current/doxygen/';
+
+find(sub {
+         if ($_ =~ /\.html$/)
+         {
+              push(@html, $File::Find::name);
+         }
+     }, "./");
+chomp(@html);
+
+for my $filename (@html) {
+     if ($filename eq "./header.html")
+     {
+         # there is no relevant content in the header
+     }
+
+     open(my $file_handle, "+<:encoding(UTF-8)", $filename)
+         or die "Could not read $filename: $!";
+
+     my $match = 0;
+     while (my $line = <$file_handle>)
+     {
+         if (index($line, '<link rel="canonical"') != -1)
+         {
+              $match = 1;
+              last;
+         }
+     }
+
+     my $new_text_data = "";
+     if ( ! $match )
+     {
+         seek($file_handle, 0, 0)
+              or die "Could not seek $filename: $!";
+
+         my $canonical_link_added = 0;
+         while (my $line = <$file_handle>)
+         {
+              $new_text_data .= $line;
+
+              # Do not add canonical link twice
+              if ( ! $canonical_link_added and index($line, '<head>') != -1)
+              {
+                   die unless substr($filename, 0, 2) eq "./";
+
+                   $new_text_data .= $link_start . substr($filename, 2) . '" />' . "\n";
+                   $canonical_link_added = 1;
+              }
+         }
+     }
+
+     if (length($new_text_data) > 0)
+     {
+         # Truncate the file and write the new text
+         seek($file_handle, 0, 0)
+              or die "Could not seek $filename: $!";
+         print $file_handle $new_text_data;
+
+         truncate($file_handle, tell($file_handle))
+              or die "Could not truncate $filename: $!";
+         close($file_handle)
+              or die "Could not close $filename: $!";
+     }
+}
diff --git a/doc/doxygen/scripts/set_canonical_doxygen.py b/doc/doxygen/scripts/set_canonical_doxygen.py
deleted file mode 100755 (executable)
index 4d6d8b3..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-#!/usr/bin/env python
-## ---------------------------------------------------------------------
-##
-## Copyright (C) 2019 by the deal.II authors
-##
-## This file is part of the deal.II library.
-##
-## The deal.II library is free software; you can use it, redistribute
-## it, and/or modify it under the terms of the GNU Lesser General
-## Public License as published by the Free Software Foundation; either
-## version 2.1 of the License, or (at your option) any later version.
-## The full text of the license can be found in the file LICENSE at
-## the top level of the deal.II distribution.
-##
-## ---------------------------------------------------------------------
-
-# This script sets the canonical webpage for all the webpages of the
-# doxygen documentation. For more information see
-# https://en.wikipedia.org/wiki/Canonical_link_element
-#
-# This script is invoked by CMake. To add the canonical link to the webpages of
-# the deal.ii repository you can use the script
-# contrib/utilities/set_canonical_webpages.py
-
-import os
-
-LINK_START = ('<link rel="canonical" href="https://www.dealii.org/current'
-              + '/doxygen/')
-
-def filename_generator():
-    for root, _, file_names in os.walk("./"):
-        for file_name in file_names:
-            if file_name.endswith(".html"):
-                if root == "./":
-                    yield root + file_name
-                else:
-                    yield root + "/" + file_name
-
-for filename in filename_generator():
-    # there is no relevant content in the header
-    if filename == "./header.html":
-        pass
-    new_text_data = str()
-    with open(filename, 'r') as file_handle:
-        if '<link rel="canonical"' not in file_handle.read():
-            file_handle.seek(0)
-            for line in file_handle.readlines():
-                # Do not add the canonical link twice
-                canonical_link_added = False
-                new_text_data += line
-                if not canonical_link_added and '<head>' in line:
-                    assert filename[:2] == "./"
-                    new_text_data += LINK_START + filename[2:] + '" />\n'
-                    canonical_link_added = True
-    if new_text_data:
-        # Truncate the file and write the new text
-        with open(filename, 'w+') as file_handle:
-            file_handle.write(new_text_data)

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.